File tree 2 files changed +24
-0
lines changed
packages/aws-cdk-lib/aws-lambda
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ export class FunctionUrl extends Resource implements IFunctionUrl {
229
229
}
230
230
231
231
private renderCors ( cors : FunctionUrlCorsOptions ) : CfnUrl . CorsProperty {
232
+ if ( cors . maxAge && ! cors . maxAge . isUnresolved ( ) && cors . maxAge . toSeconds ( ) > 86400 ) {
233
+ throw new Error ( `FunctionUrl CORS maxAge should be less than or equal to 86400 secs (got ${ cors . maxAge . toSeconds ( ) } )` ) ;
234
+ }
235
+
232
236
return {
233
237
allowCredentials : cors . allowCredentials ,
234
238
allowHeaders : cors . allowedHeaders ,
Original file line number Diff line number Diff line change @@ -140,6 +140,26 @@ describe('FunctionUrl', () => {
140
140
} ) . toThrow ( / F u n c t i o n U r l c a n n o t b e u s e d w i t h a V e r s i o n / ) ;
141
141
} ) ;
142
142
143
+ test ( 'throws when CORS maxAge is greater than 86400 secs' , ( ) => {
144
+ // GIVEN
145
+ const stack = new cdk . Stack ( ) ;
146
+ const fn = new lambda . Function ( stack , 'MyLambda' , {
147
+ code : new lambda . InlineCode ( 'hello()' ) ,
148
+ handler : 'index.hello' ,
149
+ runtime : lambda . Runtime . NODEJS_14_X ,
150
+ } ) ;
151
+
152
+ // WHEN
153
+ expect ( ( ) => {
154
+ new lambda . FunctionUrl ( stack , 'FunctionUrl' , {
155
+ function : fn ,
156
+ cors : {
157
+ maxAge : cdk . Duration . seconds ( 86401 ) ,
158
+ } ,
159
+ } ) ;
160
+ } ) . toThrow ( / F u n c t i o n U r l C O R S m a x A g e s h o u l d b e l e s s t h a n o r e q u a l t o 8 6 4 0 0 s e c s / ) ;
161
+ } ) ;
162
+
143
163
test ( 'grantInvokeUrl: adds appropriate permissions' , ( ) => {
144
164
// GIVEN
145
165
const stack = new cdk . Stack ( ) ;
You can’t perform that action at this time.
0 commit comments