npx cdk bootstrap aws://ACCOUNT-NUMBER/REGION
5. Sau khi khởi động, đi đến CloudFormation. Bạn sẽ thấy một stack tên là CDKToolkit vừa được tạo.
Sau khi chúng ta khởi động xong tài khoản và vùng AWS, chúng ta đã sẵn sàng xây dựng và triển khai ứng dụng CDK.
npm run build
git add .
git commit -m "empty pipeline"
git push
Nhập GitHub username và access token nếu được yêu cầu.
npx cdk deploy
Nhập Y nếu được yêu cầu.
Cho đến nay, chúng ta đã cung cấp một đường ống rỗng và đường ống đó vẫn chưa triển khai ứng dụng web của chúng ta. Bây giờ, chúng ta sẽ tạo một giai đoạn để triển khai ứng dụng lên 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