File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
packages/@aws-cdk/aws-lambda Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,12 @@ export class Function extends FunctionBase {
347
347
this . role . addToPolicy ( statement ) ;
348
348
}
349
349
350
+ const stack = cdk . Stack . find ( this ) ;
351
+ const isChina = stack . env . region && stack . env . region . startsWith ( 'cn-' ) ;
352
+ if ( isChina && props . environment && Object . keys ( props . environment ) . length > 0 ) {
353
+ throw new Error ( `Environment variables are not supported in this region (${ stack . env . region } ); consider using tags or SSM parameters instead` ) ;
354
+ }
355
+
350
356
const resource = new CfnFunction ( this , 'Resource' , {
351
357
functionName : props . functionName ,
352
358
description : props . description ,
Original file line number Diff line number Diff line change @@ -1178,6 +1178,52 @@ export = {
1178
1178
test . done ( ) ;
1179
1179
} ,
1180
1180
1181
+ 'environment variables are prohibited in China' ( test : Test ) {
1182
+ // GIVEN
1183
+ const stack = new cdk . Stack ( undefined , undefined , { env : { region : 'cn-north-1' } } ) ;
1184
+
1185
+ // WHEN
1186
+ test . throws ( ( ) => {
1187
+ new lambda . Function ( stack , 'MyLambda' , {
1188
+ code : new lambda . InlineCode ( 'foo' ) ,
1189
+ handler : 'index.handler' ,
1190
+ runtime : lambda . Runtime . NodeJS ,
1191
+ environment : {
1192
+ SOME : 'Variable'
1193
+ }
1194
+ } ) ;
1195
+ } , / E n v i r o n m e n t v a r i a b l e s a r e n o t s u p p o r t e d / ) ;
1196
+
1197
+ test . done ( ) ;
1198
+ } ,
1199
+
1200
+ 'environment variables work in an unspecified region' ( test : Test ) {
1201
+ // GIVEN
1202
+ const stack = new cdk . Stack ( ) ;
1203
+
1204
+ // WHEN
1205
+ new lambda . Function ( stack , 'MyLambda' , {
1206
+ code : new lambda . InlineCode ( 'foo' ) ,
1207
+ handler : 'index.handler' ,
1208
+ runtime : lambda . Runtime . NodeJS ,
1209
+ environment : {
1210
+ SOME : 'Variable'
1211
+ }
1212
+ } ) ;
1213
+
1214
+ // THEN
1215
+ expect ( stack ) . to ( haveResource ( 'AWS::Lambda::Function' , {
1216
+ Environment : {
1217
+ Variables : {
1218
+ SOME : "Variable"
1219
+ }
1220
+ }
1221
+ } ) ) ;
1222
+
1223
+ test . done ( ) ;
1224
+
1225
+ } ,
1226
+
1181
1227
'support reserved concurrent executions' ( test : Test ) {
1182
1228
const stack = new cdk . Stack ( ) ;
1183
1229
You can’t perform that action at this time.
0 commit comments