I'm using CDK to create a stack with some ELB resources. Everything seems to be working correctly, but I end up with two CloudFormation stacks. One named demo and another that has a randomly generated name like awseb-e-jkmuguqm3e-stack.
The demo stack has the ElasticBeanstalk Application and Environment, but the other stack has a bunch of load balancer resources, including an AutoScalingGroup, LaunchConfiguration, ScalingPolicy, etc, that I assume are created as part of the ELB stuff, but I would think they'd end up in the same stack?
disclaimer: this might be entirely expected behavior, as everything works, but being new to CDK I figured someone might know why i get an extra stack here, and maybe there is something I can do to prevent it
I've defined an AppStack (cdk-app/index.ts):
export class AppStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const stackName = _.get(props, ['stackName'], '');
const app = new elasticBeanstalk.CfnApplication(this, `${stackName}EbsApplication`, {
applicationName: `${_.toLower(stackName)}-ebs-app`
});
const ebsInstanceRole = new iam.Role(
this,
`${stackName}EBSInstanceRole`,
{
roleName: `${_.toLower(stackName)}-ebs-role`,
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
}
);
// create an instance profile the that instances in our EBS environment will use
const ebsInstanceProfile = new iam.CfnInstanceProfile(
this,
`${stackName}InstanceProfile`,
{
instanceProfileName: `${_.toLower(stackName)}-ebs-instance-profile`,
roles: [
ebsInstanceRole.roleName,
],
}
);
const env = new elasticBeanstalk.CfnEnvironment(this, 'Environment', {
environmentName: `${_.toLower(stackName)}-ebs-env`,
applicationName: `${_.toLower(stackName)}-ebs-app`,
solutionStackName: '64bit Amazon Linux 2 v5.0.2 running Node.js 12',
optionSettings: [
{
namespace: 'aws:autoscaling:launchconfiguration',
optionName: 'IamInstanceProfile',
value: ebsInstanceProfile.instanceProfileName,
}
]
});
}
}
export default AppStack;
I use the stack (index.ts):
import AppStack from "./cdk-app";
const app = new cdk.App();
const appStack = new AppStack(app, 'demoAppStack', { stackName: 'demo' });
app.synth();
export class AppStack extends cdk.Stackandexport default AppStack;2. How are you importing the stack when you are using it just beforeapp.synth();? - dmahapatroimport App stack from '../AppStack', I'll update example code. It is exporting twice but I don't think that should matter (the named export doesn't get used). Thank you for looking it over. - Donald P