aws-cdk-lib#Annotations TypeScript Examples
The following examples show how to use
aws-cdk-lib#Annotations.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: aws-image-builder-stack.ts From amazon-ec2-image-builder-samples with MIT No Attribution | 6 votes |
getData = (dir: string, file: string) => {
const filePath = path.join(__dirname, "..", dir, file);
if (!existsSync(filePath)) {
Annotations.of(this).addError(
`Component file ${filePath} does not exists`
);
return "";
}
return readFileSync(path.join(__dirname, "..", dir, file)).toString();
};
Example #2
Source File: aws-image-builder.ts From amazon-ec2-image-builder-samples with MIT No Attribution | 6 votes |
private subscribeEmails(notificationTopic: ITopic) {
const emails = this.node.tryGetContext("buildCompletionNotificationEmails");
if (emails) {
if (!Array.isArray(emails)) {
Annotations.of(this).addWarning(
"buildCompletionNotificationEmails contains invalid value it should be a list of emails, skip subscription"
);
} else {
(<Array<string>>emails).forEach((email) =>
notificationTopic.addSubscription(new EmailSubscription(email))
);
}
}
}
Example #3
Source File: aws-image-builder-stack.ts From amazon-ec2-image-builder-samples with MIT No Attribution | 5 votes |
validAndGetPipelineConfiguration() {
// Get pipeline details from json
const imageBuilderPipelineConfigurations = this.node.tryGetContext(
"ImageBuilderPipelineConfigurations"
);
if (
imageBuilderPipelineConfigurations ||
imageBuilderPipelineConfigurations === ""
) {
if (Array.isArray(imageBuilderPipelineConfigurations)) {
if (imageBuilderPipelineConfigurations.length === 0) {
Annotations.of(this).addError(
"An ImageBuilder pipeline configuration list requires at least one configration, found 0"
);
return;
}
if (
(<Array<PipelineConfig>>imageBuilderPipelineConfigurations).some(
(pipeConfig) =>
!pipeConfig.name ||
!pipeConfig.dir ||
!pipeConfig.instanceProfileName ||
!pipeConfig.version ||
!pipeConfig.cfnImageRecipeName ||
!pipeConfig.parentImage
)
) {
Annotations.of(this).addError(
"An ImageBuilder pipeline configuration is missing one of the following required values: name, dir, instanceProfileName, version, cfnImageRecipeName, parentImage"
);
return;
}
} else {
Annotations.of(this).addError(
"The imageBuilderPipelinesConfiguration variable must be an array"
);
return;
}
} else {
Annotations.of(this).addError(
"Mandaotry configuration ImageBuilderPipelineConfigurations is missing, expecting a list of pipeline configurations"
);
return;
}
return imageBuilderPipelineConfigurations;
}
Example #4
Source File: index.ts From cdk-ssm-document with Apache License 2.0 | 5 votes |
/**
* Defines a new SSM document
*/
constructor(scope: Construct, id: string, props: DocumentProps) {
super(scope, id);
this.tags = new TagManager(TagType.MAP, 'Custom::SSM-Document');
this.tags.setTag(createdByTag, ID);
const stack = Stack.of(this).stackName;
this.lambda = this.ensureLambda();
const name = this.fixDocumentName(props.name);
if (name.length < 3 || name.length > 128) {
Annotations.of(this).addError(
`SSM Document name ${name} is invalid. The name must be between 3 and 128 characters.`
);
return;
}
let content = props.content;
if (typeof content === 'string') {
content = yaml.safeLoad(content) as DocumentContent;
}
const document = new CustomResource(this, `SSM-Document-${name}`, {
serviceToken: this.lambda.functionArn,
resourceType: resourceType,
properties: {
updateDefaultVersion: props.updateDefaultVersion || true,
name: name,
content: content,
documentType: props.documentType || 'Command',
targetType: props.targetType || '/',
attachments: props.attachments,
versionName: props.versionName,
StackName: stack,
tags: Lazy.any({
produce: () => this.tags.renderTags(),
}),
},
pascalCaseProperties: true,
});
this.name = document.getAttString('Name');
}
Example #5
Source File: index.ts From cdk-ec2-key-pair with Apache License 2.0 | 4 votes |
/**
* Defines a new EC2 Key Pair. The private key will be stored in AWS Secrets Manager
*/
constructor(scope: Construct, id: string, props: KeyPairProps) {
super(scope, id);
if (
props.removeKeySecretsAfterDays &&
(props.removeKeySecretsAfterDays < 0 ||
(props.removeKeySecretsAfterDays > 0 &&
props.removeKeySecretsAfterDays < 7) ||
props.removeKeySecretsAfterDays > 30)
) {
Annotations.of(this).addError(
`Parameter removeKeySecretsAfterDays must be 0 or between 7 and 30. Got ${props.removeKeySecretsAfterDays}`
);
}
if (
props.publicKey?.length &&
props.publicKeyFormat !== undefined &&
props.publicKeyFormat !== PublicKeyFormat.OPENSSH
) {
Annotations.of(this).addError(
'When importing a key, the format has to be of type OpenSSH'
);
}
const stack = Stack.of(this).stackName;
this.prefix = props.resourcePrefix || stack;
if (this.prefix.length + cleanID.length > 62)
// Cloudformation limits names to 63 characters.
Annotations.of(this).addError(
`Cloudformation limits names to 63 characters.
Prefix ${this.prefix} is too long to be used as a prefix for your roleName. Define parameter resourcePrefix?:`
);
this.lambda = this.ensureLambda();
this.tags = new TagManager(TagType.MAP, 'Custom::EC2-Key-Pair');
this.tags.setTag(createdByTag, ID);
const kmsPrivate = props.kmsPrivateKey || props.kms;
const kmsPublic = props.kmsPublicKey || props.kms;
const key = new CustomResource(this, `EC2-Key-Pair-${props.name}`, {
serviceToken: this.lambda.functionArn,
resourceType: resourceType,
properties: {
Name: props.name,
Description: props.description || '',
KmsPrivate: kmsPrivate?.keyArn || 'alias/aws/secretsmanager',
KmsPublic: kmsPublic?.keyArn || 'alias/aws/secretsmanager',
PublicKey: props.publicKey || '',
StorePublicKey: props.storePublicKey || false,
ExposePublicKey: props.exposePublicKey || false,
PublicKeyFormat: props.publicKeyFormat || PublicKeyFormat.OPENSSH,
RemoveKeySecretsAfterDays: props.removeKeySecretsAfterDays || 0,
SecretPrefix: props.secretPrefix || 'ec2-ssh-key/',
StackName: stack,
Tags: Lazy.any({
produce: () => this.tags.renderTags(),
}),
},
});
if (typeof props.kms !== 'undefined') {
props.kms.grantEncryptDecrypt(this.lambda.role!);
key.node.addDependency(props.kms);
key.node.addDependency(this.lambda.role!);
}
if (typeof props.kmsPrivateKey !== 'undefined') {
props.kmsPrivateKey.grantEncryptDecrypt(this.lambda.role!);
key.node.addDependency(props.kmsPrivateKey);
key.node.addDependency(this.lambda.role!);
}
if (typeof props.kmsPublicKey !== 'undefined') {
props.kmsPublicKey.grantEncryptDecrypt(this.lambda.role!);
key.node.addDependency(props.kmsPublicKey);
key.node.addDependency(this.lambda.role!);
}
this.privateKeyArn = key.getAttString('PrivateKeyARN');
this.publicKeyArn = key.getAttString('PublicKeyARN');
this.publicKeyValue = key.getAttString('PublicKeyValue');
this.keyPairName = key.getAttString('KeyPairName');
this.keyPairID = key.getAttString('KeyPairID');
}