cd ..
mkdir cdk-pipeline-eb-demo
cd cdk-pipeline-eb-demo
If your NodeJS application is still running, press Ctrl + C to stop.
npx cdk init app --language typescript
git branch -m main
cp -r ../my_webapp ./src
echo '!src/*' >> .gitignore
echo 'src/package-lock.json' >> .gitignore
echo 'src/node_modules' >> .gitignore
git add .
git commit -m "initial commit"
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPOSITORY.git
git config credential.helper 'cache --timeout=3600'
git push -u origin main
Mật khẩu là access token của tài khoản GitHub được tạo ra ở bước 2.1- Create GitHub repository
Chúng ta sẽ xóa tệp mặc định được tạo ra bởi CDK và triển khai code cho stack tài nguyên ElasticBeanstalk.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
// Add import statements here
export interface EBEnvProps extends cdk.StackProps {
// Autoscaling group configuration
minSize?: string;
maxSize?: string;
instanceTypes?: string;
envName?: string;
}
export class EBApplnStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: EBEnvProps) {
super(scope, id, props);
// The code that defines your stack goes here
}
}
Một stack tài nguyên là một tập hợp các tài nguyên cơ sở hạ tầng đám mây - trong trường hợp này là tất cả tài nguyên AWS — sẽ được cung cấp trong một tài khoản cụ thể. Tài khoản nơi các tài nguyên này sẽ được cung cấp là stack mà bạn đã đặt cấu hình trong điều kiện tiên quyết. Trong stack tài nguyên này, chúng ta sẽ tạo các tài nguyên sau:
import * as s3assets from 'aws-cdk-lib/aws-s3-assets';
// Construct an S3 asset Zip from directory up.
const webAppZipArchive = new s3assets.Asset(this, 'WebAppZip', {
path: `${__dirname}/../src`,
});