Working on AWS CDK TYPESCRIPT to deploy the Beanstalk app. I was able to setup a beanstalk app using AWS CDK Typescript but could not find a way to set up it in existing VPC with high availability. this is my ebstack.ts
#!/usr/bin/env node
import cdk = require('@aws-cdk/core');
import elasticbeanstalk = require('@aws-cdk/aws-elasticbeanstalk');
export class ElbtestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
//objects for access parameters
const node = this.node;
const appName = 'DEVELOPMENT';
const platform = node.tryGetContext("platform");
const app = new elasticbeanstalk.CfnApplication(this, 'Application', {
applicationName: appName
});
const optionSettingProperties: elasticbeanstalk.CfnEnvironment.OptionSettingProperty[] = [
{
namespace: 'aws:autoscaling:launchconfiguration',
optionName: 'InstanceType',
value: 't3.small',
},
{
namespace: 'aws:autoscaling:launchconfiguration',
optionName: 'IamInstanceProfile',
// Here you could reference an instance profile by ARN (e.g. myIamInstanceProfile.attrArn)
// For the default setup, leave this as is (it is assumed this role exists)
// https://stackoverflow.com/a/55033663/6894670
value: 'aws-elasticbeanstalk-ec2-role',
},
{
namespace: 'aws:elasticbeanstalk:container:nodejs',
optionName: 'NodeVersion',
value: '10.16.3',
}
];
new elasticbeanstalk.CfnEnvironment(this, 'Environment', {
environmentName: 'x-SERVICE',
applicationName: app.applicationName || appName,
solutionStackName: '64bit Amazon Linux 2018.03 v4.13.1 running Node.js',
optionSettings: optionSettingProperties,
});
}
}
I am following AWS Provided examples https://github.com/aws-samples/aws-cdk-examples How can I set Subnet to deploy this beanstalk app with high-availability?
For a complete list of namespaces and options:
It's just as an example.
import cdk = require('@aws-cdk/core');
import {IVpc, Peer, Port, SecurityGroup,} from "@aws-cdk/aws-ec2";
import {CfnApplication, CfnEnvironment} from '@aws-cdk/aws-elasticbeanstalk';
interface ApplicationStackProps extends cdk.StackProps {
vpc: IVpc;
}
export class ApplicationStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: ApplicationStackProps) {
super(scope, id, props);
const prj: string = this.node.tryGetContext("prj");
const stage: string = this.node.tryGetContext("stage");
const platform: string = this.node.tryGetContext("platform");
const albSecurityGroup = new SecurityGroup(this, 'albSecurityGroup', {
allowAllOutbound: true,
securityGroupName: 'alb-sg',
vpc: props.vpc,
});
albSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.tcp(80));
albSecurityGroup.addIngressRule(Peer.anyIpv4(), Port.tcp(443));
const app = new CfnApplication(this, 'Application', {
applicationName: `${prj}-${stage}-application`
});
const optionSettings: CfnEnvironment.OptionSettingProperty[] = [
{
namespace: 'aws:ec2:vpc',
optionName: 'VPCId',
value: props.vpc.vpcId,
},
{
namespace: 'aws:ec2:vpc',
optionName: 'ELBSubnets',
value: props.vpc.publicSubnets.map(value => value.subnetId).join(','),
}
,
{
namespace: 'aws:ec2:vpc',
optionName: 'Subnets',
value: props.vpc.privateSubnets.map(value => value.subnetId).join(','),
}
];
const env = new CfnEnvironment(this, 'Environment', {
environmentName: 'Environment',
applicationName: app.applicationName || `${prj}-${stage}-application`,
platformArn: platform,
optionSettings: optionSettings,
});
}
}