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
Password is the access token of your GitHub account had been generated at step 2.1- Create GitHub repository
We are going to delete the default file created by CDK and define our own code for all the ElasticBeanstalk resources stack.
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
}
}
A resource stack is a set of cloud infrastructure resources—all AWS resources in this case—that will be provisioned into a specific account. The account where these resources will be provisioned is the stack that you configured in the prerequisite. In this resource stack, we are going to create these resources:
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`,
});