I'd like to set an environment variable that's available in my Nodejs application that's deployed to Elastic Beanstalk using AWS CDK. I've tried to add it to the Environment options, but the deployment gets stuck for several minutes until I manually cancel the stack update.
Here's how I tried to add the environment variable, according to the docs from AWS:
{
namespace: 'aws:elasticbeanstalk:application:environment',
optionName: 'CORS_ALLOW_ORIGIN',
value:
'http://my-frontend.s3-website.eu-central-1.amazonaws.com'
}
I've also tried adding the value using 'http...' and '"http..."' without success.
Here's the complete script:
#!/usr/bin/env node
import cdk = require('@aws-cdk/core');
import ebs = require('@aws-cdk/aws-elasticbeanstalk');
export class MyPrototype extends cdk.Stack {
public constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const appName = 'MyPrototypeApp';
const platform = this.node.tryGetContext('platform');
const app = new ebs.CfnApplication(this, 'Application', {
applicationName: appName
});
const options: ebs.CfnEnvironment.OptionSettingProperty[] = [
{
namespace: 'aws:autoscaling:launchconfiguration',
optionName: 'IamInstanceProfile',
value: 'aws-elasticbeanstalk-ec2-role'
},
{
namespace: 'aws:elasticbeanstalk:container:nodejs',
optionName: 'NodeVersion',
value: '10.15.0'
},
{
namespace: 'aws:elasticbeanstalk:application:environment',
optionName: 'CORS_ALLOW_ORIGIN',
value:
'http://my-frontend.s3-website.eu-central-1.amazonaws.com'
}
];
new ebs.CfnEnvironment(this, 'Environment', {
environmentName: 'MyPrototypeEnvironment',
applicationName: app.applicationName || appName,
platformArn: platform,
optionSettings: options
});
}
}
const app = new cdk.App();
new MyPrototype(app, 'ElasticBeanstalk');
app.synth();
Not sure why it's failing because that's the way of setting env variables, inside the optionSettings, using 'aws:elasticbeanstalk:application:environment' as namespace (also you can add multiple namespaces with the same name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With