npx cdk bootstrap aws://ACCOUNT-NUMBER/REGION
5. After bootstraping, go to CloudFormation. You will see a stack name CDKToolkit had been provisioned.
After we have bootstrapped our AWS account and Region, we are ready to build and deploy our CDK application.
npm run build
git add .
git commit -m "empty pipeline"
git push
Input the GitHub username and access token if necessary.
npx cdk deploy
Enter Y if was requested.
So far, we have provisioned an empty pipeline, and the pipeline isn’t deploying our web application yet. Now, we will create a stage to deploy application to Elastic Beanstalk.
import { Stage } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { EBEnvProps, EBApplnStack } from './eb-appln-stack';
/**
* Deployable unit of web service app
*/
export class CdkEBStage extends Stage {
constructor(scope: Construct, id: string, props?: EBEnvProps) {
super(scope, id, props);
const service = new EBApplnStack(this, 'WebService', {
minSize : props?.minSize,
maxSize : props?.maxSize,
instanceTypes : props?.instanceTypes,
envName : props?.envName
} );
}
}
import { CdkEBStage } from './eb-stage';
// deploy beanstalk app
// For environment with all default values:
// const deploy = new CdkEBStage(this, 'Pre-Prod');
// For environment with custom AutoScaling group configuration
const deploy = new CdkEBStage(this, 'Pre-Prod', {
minSize : "1",
maxSize : "2"
});
const deployStage = pipeline.addStage(deploy);
npm run build
git add .
git commit -m 'Add Pre-Prod stage'
git push