@aws-cdk/core#App TypeScript Examples
The following examples show how to use
@aws-cdk/core#App.
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: stack.ts From aws-boilerplate with MIT License | 6 votes |
constructor(scope: App, id: string, props: EnvDbStackProps) {
super(scope, id, props);
const {envSettings} = props;
const mainVpc = this.retrieveMainVpc(props);
this.mainDatabase = new MainDatabase(this, "MainDatabase", {
envSettings,
vpc: mainVpc,
fargateContainerSecurityGroup: this.retrieveFargateContainerSecurityGroup(props),
lambdaSecurityGroup: this.retrieveLambdaSecurityGroup(props),
});
}
Example #2
Source File: stack.ts From aws-boilerplate with MIT License | 6 votes |
constructor(scope: App, id: string, props: EnvMainStackProps) {
super(scope, id, props);
const {envSettings} = props;
this.mainVpc = new MainVpc(this, "MainVPC", {envSettings});
this.mainCertificates = new MainCertificates(this, "MainCertificates", {
envSettings,
});
this.mainEcsCluster = new MainECSCluster(this, "MainECSCluster", {
envSettings,
vpc: this.mainVpc.vpc,
certificate: this.mainCertificates.certificate,
});
this.mainKmsKey = new MainKmsKey(this, "MainKMSKey", {envSettings});
this.mainLambdaConfig = new MainLambdaConfig(this, "MainLambdaConfig", {
envSettings,
mainVpc: this.mainVpc,
});
}
Example #3
Source File: integ.default.ts From aws-cdk-for-k3scluster with MIT License | 6 votes |
constructor() {
const app = new App();
const env = {
region: process.env.CDK_DEFAULT_REGION,
account: process.env.CDK_DEFAULT_ACCOUNT,
};
const stack = new Stack(app, 'testing-stack', { env });
const vpc = k3s.VpcProvider.getOrCreate(stack);
const cluster = new k3s.Cluster(stack, 'Cluster', {
vpc,
spotWorkerNodes: true,
workerMinCapacity: 1,
workerInstanceType: new ec2.InstanceType('m6g.medium'),
controlPlaneInstanceType: new ec2.InstanceType('m6g.medium'),
bucketRemovalPolicy: RemovalPolicy.DESTROY,
});
new CfnOutput(stack, 'EndpointURI', { value: cluster.endpointUri });
new CfnOutput(stack, 'Region', { value: Stack.of(stack).region });
this.stack = [stack];
}
Example #4
Source File: cluster.test.ts From aws-cdk-for-k3scluster with MIT License | 6 votes |
test('create the default cluster', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'testing-stack');
// WHEN
new k3s.Cluster(stack, 'Cluster');
// THEN
expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', {
MaxSize: '3',
MinSize: '3',
LaunchTemplate: {
LaunchTemplateId: {
Ref: 'ClusterWorkerLaunchTemplate84D2244A',
},
Version: {
'Fn::GetAtt': [
'ClusterWorkerLaunchTemplate84D2244A',
'LatestVersionNumber',
],
},
},
});
expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration');
});
Example #5
Source File: cluster.test.ts From aws-cdk-for-k3scluster with MIT License | 6 votes |
test('support m6g instance types', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'testing-stack');
// WHEN
new k3s.Cluster(stack, 'Cluster-test', {
bucketRemovalPolicy: RemovalPolicy.DESTROY,
controlPlaneInstanceType: new ec2.InstanceType('m6g.large'),
workerInstanceType: new ec2.InstanceType('m6g.medium'),
spotWorkerNodes: true,
});
// THEN
// worker nodes ASG
expect(stack).toHaveResourceLike('AWS::EC2::LaunchTemplate', {
LaunchTemplateData: {
ImageId: {
Ref: 'SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmarm64gp2C96584B6F00A464EAD1953AFF4B05118Parameter',
},
InstanceMarketOptions: {
MarketType: 'spot',
SpotOptions: {
SpotInstanceType: 'one-time',
},
},
InstanceType: 'm6g.medium',
},
});
// control plane ec2
expect(stack).toHaveResource('AWS::EC2::Instance', {
InstanceType: 'm6g.large',
});
});
Example #6
Source File: cluster.test.ts From aws-cdk-for-k3scluster with MIT License | 6 votes |
test('support t4g instance types', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'testing-stack');
// WHEN
new k3s.Cluster(stack, 'Cluster-test', {
bucketRemovalPolicy: RemovalPolicy.DESTROY,
controlPlaneInstanceType: new ec2.InstanceType('t4g.large'),
workerInstanceType: new ec2.InstanceType('t4g.medium'),
spotWorkerNodes: true,
});
// THEN
// worker nodes ASG
expect(stack).toHaveResourceLike('AWS::EC2::LaunchTemplate', {
LaunchTemplateData: {
ImageId: {
Ref: 'SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmarm64gp2C96584B6F00A464EAD1953AFF4B05118Parameter',
},
InstanceMarketOptions: {
MarketType: 'spot',
SpotOptions: {
SpotInstanceType: 'one-time',
},
},
InstanceType: 't4g.medium',
},
});
// control plane ec2
expect(stack).toHaveResource('AWS::EC2::Instance', {
InstanceType: 't4g.large',
});
});
Example #7
Source File: application-stack.ts From aws-cross-account-cicd-pipeline with MIT No Attribution | 6 votes |
constructor(app: App, id: string, props: ApplicationStackProps) {
super(app, id, props);
this.lambdaCode = lambda.Code.fromCfnParameters();
const func = new lambda.Function(this, 'Lambda', {
functionName: 'HelloLambda',
code: this.lambdaCode,
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_12_X,
environment: {
STAGE_NAME: props.stageName
}
});
new apigateway.LambdaRestApi(this, 'HelloLambdaRestApi', {
handler: func,
endpointExportName: 'HelloLambdaRestApiEmdpoint',
deployOptions: {
stageName: props.stageName
}
});
const version = func.addVersion(new Date().toISOString());
const alias = new lambda.Alias(this, 'LambdaAlias', {
aliasName: props.stageName,
version,
});
new codedeploy.LambdaDeploymentGroup(this, 'DeploymentGroup', {
alias,
deploymentConfig: codedeploy.LambdaDeploymentConfig.ALL_AT_ONCE,
});
}
Example #8
Source File: repository-stack.ts From aws-cross-account-cicd-pipeline with MIT No Attribution | 6 votes |
constructor(app: App, id: string, props?: StackProps) {
super(app, id, props);
new codecommit.Repository(this, 'CodeCommitRepo', {
repositoryName: `repo-${this.account}`
});
}
Example #9
Source File: cicd-stack.ts From MDDL with MIT License | 5 votes |
/**
* Create a CDK app from a pipeline config by dynamically adding stacks to it
* @param props The pipeline config which determines stacks that are in the app
* @param app The CDK app to use (optional - will create a new one if not provided)
*/
public static buildApp(props: Props, app = new App()) {
// read out configuration
const { developStageConfiguration, prodStageConfiguration } = props
const cityStacksProps = CiCdStack.getCityStacksProps(props)
const createdStacks: { name: string; stack: Stack }[] = []
const integratedConfigs = [developStageConfiguration]
if (prodStageConfiguration) {
integratedConfigs.push(prodStageConfiguration)
}
for (const integratedConfig of integratedConfigs) {
const { authStackProps, dataStoreStackProps } = integratedConfig
// add auth stack
if (authStackProps) {
const authStack = new AuthStack(
app,
authStackProps.name,
authStackProps.props,
)
createdStacks.push({ name: authStackProps.name, stack: authStack })
}
// add data store stack
const dataStoreStack = new DataStoreStack(
app,
dataStoreStackProps.name,
dataStoreStackProps.props,
)
createdStacks.push({
name: dataStoreStackProps.name,
stack: dataStoreStack,
})
}
// add all city stacks
cityStacksProps.map((stackProps) => {
const { name, props } = stackProps
// find auth stack, if any
const authStack = props.authStackName
? (createdStacks.find((cs) => cs.name == props.authStackName)
?.stack as AuthStack)
: undefined
// find data store stack
const dataStoreStack = createdStacks.find(
(cs) => cs.name == props.dataStoreStackName,
)?.stack as DataStoreStack
// add stack
const stack = new CityStack(app, name, {
...props,
authStack,
dataStoreStack,
})
createdStacks.push({ name, stack })
})
return { app, createdStacks }
}
Example #10
Source File: cdk-app.ts From cdk-datadog-resources with Apache License 2.0 | 5 votes |
app = new App()
Example #11
Source File: test.ts From aws-cdk-webpack-lambda-function with MIT License | 5 votes |
test("CloudFormation Test", () => {
// prepare
const stack = new TestStack(new App(), "TestStack");
const resources = SynthUtils.toCloudFormation(stack)["Resources"];
expect(resources).toMatchSnapshot();
});
Example #12
Source File: TestStack.ts From aws-cdk-webpack-lambda-function with MIT License | 5 votes |
app = new App()
Example #13
Source File: main.test.ts From keycloak-on-aws with Apache License 2.0 | 5 votes |
test('Snapshot', () => {
const app = new App();
const stack = new KeycloakStack(app, 'test', { fromExistingVPC: true });
expect(stack).not.toHaveResource('AWS::S3::Bucket');
expect(app.synth().getStackArtifact(stack.artifactId).template).toMatchSnapshot();
});
Example #14
Source File: main.ts From keycloak-on-aws with Apache License 2.0 | 5 votes |
app = new App()
Example #15
Source File: main.ts From keycloak-on-aws with Apache License 2.0 | 5 votes |
function mkstack(a: App, id: string) {
return new KeycloakStack(a, id, {
auroraServerless: id.includes('aurora'),
fromExistingVPC: id.includes('existing-vpc'),
synthesizer: newSynthesizer(),
});
}
Example #16
Source File: pipeline.ts From aws-cross-account-cicd-pipeline with MIT No Attribution | 5 votes |
app = new App()
Example #17
Source File: cluster.test.ts From aws-cdk-for-k3scluster with MIT License | 5 votes |
test('add s3 removalPolicy', () => {
const app = new App();
const stack = new Stack(app, 'testing-stack');
new k3s.Cluster(stack, 'Cluster-s3-removalPolicy', {
bucketRemovalPolicy: RemovalPolicy.DESTROY,
});
expect(stack).toHaveResource('AWS::S3::Bucket');
});
Example #18
Source File: rds-stack.ts From awsmug-serverless-graphql-api with MIT License | 5 votes |
constructor(scope: App, id: string, props: RDSStackProps) {
super(scope, id, props);
this.rdsPassword = Secret.fromSecretNameV2(
this,
"rdsPassword",
"rdsPassword"
);
this.postgresRDSInstance = new DatabaseInstance(
this,
"postgres-rds-instance",
{
engine: DatabaseInstanceEngine.postgres({
version: PostgresEngineVersion.VER_10_15,
}),
vpc: props.vpc,
credentials: {
username: this.rdsDbUser,
password: this.rdsPassword.secretValue,
},
securityGroups: [props.securityGroup],
vpcPlacement: { subnetType: SubnetType.ISOLATED },
storageEncrypted: true,
multiAz: false,
allocatedStorage: 25,
storageType: StorageType.GP2,
databaseName: this.rdsDbName,
port: this.rdsPort,
}
);
this.rdsEndpointOutput = new CfnOutput(this, "rdsEndpoint", {
value: this.postgresRDSInstance.instanceEndpoint.socketAddress,
description: "Endpoint to access RDS instance",
});
this.rdsUsernameOutput = new CfnOutput(this, "rdsUsername", {
value: this.rdsDbUser,
description: "Root user of RDS instance",
});
this.rdsDatabaseOutput = new CfnOutput(this, "rdsDatabase", {
value: this.rdsDbName,
description: "Default database of RDS instance",
});
}
Example #19
Source File: app.ts From awsmug-serverless-graphql-api with MIT License | 5 votes |
app = new App()
Example #20
Source File: pipeline-stack.ts From aws-cross-account-cicd-pipeline with MIT No Attribution | 4 votes |
constructor(app: App, id: string, props: PipelineStackProps) {
super(app, id, props);
const repository = codecommit.Repository.fromRepositoryName(this, 'CodeCommitRepo', `repo-${this.account}`);
const prodDeploymentRole = iam.Role.fromRoleArn(this, 'ProdDeploymentRole', `arn:aws:iam::${props.prodAccountId}:role/CloudFormationDeploymentRole`, {
mutable: false
});
const prodCrossAccountRole = iam.Role.fromRoleArn(this, 'ProdCrossAccountRole', `arn:aws:iam::${props.prodAccountId}:role/CodePipelineCrossAccountRole`, {
mutable: false
});
const prodAccountRootPrincipal = new iam.AccountPrincipal(props.prodAccountId);
const key = new kms.Key(this, 'ArtifactKey', {
alias: 'key/artifact-key',
});
key.grantDecrypt(prodAccountRootPrincipal);
key.grantDecrypt(prodCrossAccountRole);
const artifactBucket = new s3.Bucket(this, 'ArtifactBucket', {
bucketName: `artifact-bucket-${this.account}`,
removalPolicy: RemovalPolicy.DESTROY,
encryption: s3.BucketEncryption.KMS,
encryptionKey: key
});
artifactBucket.grantPut(prodAccountRootPrincipal);
artifactBucket.grantRead(prodAccountRootPrincipal);
const cdkBuild = new codebuild.PipelineProject(this, 'CdkBuild', {
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
install: {
commands: [
'npm install'
],
},
build: {
commands: [
'npm run build',
'npm run cdk synth -- -o dist'
],
},
},
artifacts: {
'base-directory': 'dist',
files: [
'*ApplicationStack.template.json',
],
},
}),
environment: {
buildImage: codebuild.LinuxBuildImage.UBUNTU_14_04_NODEJS_10_14_1,
},
encryptionKey: key
});
const lambdaBuild = new codebuild.PipelineProject(this, 'LambdaBuild', {
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
install: {
commands: [
'cd app',
'npm install',
],
},
build: {
commands: 'npm run build',
},
},
artifacts: {
'base-directory': 'app',
files: [
'index.js',
'node_modules/**/*',
],
},
}),
environment: {
buildImage: codebuild.LinuxBuildImage.UBUNTU_14_04_NODEJS_10_14_1,
},
encryptionKey: key
});
const sourceOutput = new codepipeline.Artifact();
const cdkBuildOutput = new codepipeline.Artifact('CdkBuildOutput');
const lambdaBuildOutput = new codepipeline.Artifact('LambdaBuildOutput');
const pipeline = new codepipeline.Pipeline(this, 'Pipeline', {
pipelineName: 'CrossAccountPipeline',
artifactBucket: artifactBucket,
stages: [
{
stageName: 'Source',
actions: [
new codepipeline_actions.CodeCommitSourceAction({
actionName: 'CodeCommit_Source',
repository: repository,
output: sourceOutput,
}),
],
},
{
stageName: 'Build',
actions: [
new codepipeline_actions.CodeBuildAction({
actionName: 'Application_Build',
project: lambdaBuild,
input: sourceOutput,
outputs: [lambdaBuildOutput],
}),
new codepipeline_actions.CodeBuildAction({
actionName: 'CDK_Synth',
project: cdkBuild,
input: sourceOutput,
outputs: [cdkBuildOutput],
}),
],
},
{
stageName: 'Deploy_Dev',
actions: [
new codepipeline_actions.CloudFormationCreateUpdateStackAction({
actionName: 'Deploy',
templatePath: cdkBuildOutput.atPath('DevApplicationStack.template.json'),
stackName: 'DevApplicationDeploymentStack',
adminPermissions: true,
parameterOverrides: {
...props.devApplicationStack.lambdaCode.assign(lambdaBuildOutput.s3Location),
},
extraInputs: [lambdaBuildOutput],
})
],
},
{
stageName: 'Deploy_Prod',
actions: [
new codepipeline_actions.CloudFormationCreateUpdateStackAction({
actionName: 'Deploy',
templatePath: cdkBuildOutput.atPath('ProdApplicationStack.template.json'),
stackName: 'ProdApplicationDeploymentStack',
adminPermissions: true,
parameterOverrides: {
...props.prodApplicationStack.lambdaCode.assign(lambdaBuildOutput.s3Location),
},
deploymentRole: prodDeploymentRole,
capabilities: [cloudformation.CloudFormationCapabilities.ANONYMOUS_IAM],
extraInputs: [lambdaBuildOutput],
role: prodCrossAccountRole,
}),
],
},
],
});
pipeline.addToRolePolicy(new iam.PolicyStatement({
actions: ['sts:AssumeRole'],
resources: [`arn:aws:iam::${props.prodAccountId}:role/*`]
}));
new CfnOutput(this, 'ArtifactBucketEncryptionKeyArn', {
value: key.keyArn,
exportName: 'ArtifactBucketEncryptionKey'
});
}