-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lambda): add a synth-time check for environment variables #1690
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,12 @@ export class Function extends FunctionBase { | |
this.role.addToPolicy(statement); | ||
} | ||
|
||
const stack = cdk.Stack.find(this); | ||
const isChina = stack.env.region && stack.env.region.startsWith('cn-'); | ||
if (isChina && props.environment && Object.keys(props.environment).length > 0) { | ||
throw new Error(`Environment variables are not supported in this region (${stack.env.region}); please use tags or SSM parameters instead`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rephrase "please use" to "you may consider using" or "you can use" |
||
} | ||
|
||
const resource = new CfnFunction(this, 'Resource', { | ||
functionName: props.functionName, | ||
description: props.description, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1178,6 +1178,25 @@ export = { | |
test.done(); | ||
}, | ||
|
||
'environment variables are prohibited in China'(test: Test) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test for what happens when the region is undefined and when the region is a token |
||
// GIVEN | ||
const stack = new cdk.Stack(undefined, undefined, { env: { region: 'cn-north-1' }}); | ||
|
||
// WHEN | ||
test.throws(() => { | ||
new lambda.Function(stack, 'MyLambda', { | ||
code: new lambda.InlineCode('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NodeJS, | ||
environment: { | ||
SOME: 'Variable' | ||
} | ||
}); | ||
}, /Environment variables are not supported/); | ||
|
||
test.done(); | ||
}, | ||
|
||
'support reserved concurrent executions'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should check if
region
is not a token? (cdk.unresolved
)