File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
packages/@aws-cdk/aws-lambda Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import iam = require('@aws-cdk/aws-iam');
4
4
import sqs = require( '@aws-cdk/aws-sqs' ) ;
5
5
import cdk = require( '@aws-cdk/cdk' ) ;
6
6
import { Code } from './code' ;
7
+ import { IEventSource } from './event-source' ;
7
8
import { FunctionBase , FunctionImportProps , IFunction } from './function-base' ;
8
9
import { Version } from './lambda-version' ;
9
10
import { CfnFunction } from './lambda.generated' ;
@@ -190,6 +191,13 @@ export interface FunctionProps {
190
191
* @see https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html
191
192
*/
192
193
reservedConcurrentExecutions ?: number ;
194
+
195
+ /**
196
+ * Event sources for this function.
197
+ *
198
+ * You can also add event sources using `addEventSource`.
199
+ */
200
+ events ?: IEventSource [ ] ;
193
201
}
194
202
195
203
/**
@@ -383,6 +391,10 @@ export class Function extends FunctionBase {
383
391
for ( const layer of props . layers || [ ] ) {
384
392
this . addLayer ( layer ) ;
385
393
}
394
+
395
+ for ( const event of props . events || [ ] ) {
396
+ this . addEventSource ( event ) ;
397
+ }
386
398
}
387
399
388
400
/**
Original file line number Diff line number Diff line change @@ -1259,6 +1259,34 @@ export = {
1259
1259
Runtime : 'nodejs' } ,
1260
1260
DependsOn : [ 'MyLambdaServiceRole4539ECB6' ] } } } ) ;
1261
1261
test . done ( ) ;
1262
+ } ,
1263
+
1264
+ 'its possible to specify event sources upon creation' ( test : Test ) {
1265
+ // GIVEN
1266
+ const stack = new cdk . Stack ( ) ;
1267
+
1268
+ let bindCount = 0 ;
1269
+
1270
+ class EventSource implements lambda . IEventSource {
1271
+ public bind ( _ : lambda . FunctionBase ) : void {
1272
+ bindCount ++ ;
1273
+ }
1274
+ }
1275
+
1276
+ // WHEN
1277
+ new lambda . Function ( stack , 'fn' , {
1278
+ code : lambda . Code . inline ( 'boom' ) ,
1279
+ runtime : lambda . Runtime . NodeJS810 ,
1280
+ handler : 'index.bam' ,
1281
+ events : [
1282
+ new EventSource ( ) ,
1283
+ new EventSource ( ) ,
1284
+ ]
1285
+ } ) ;
1286
+
1287
+ // THEN
1288
+ test . deepEqual ( bindCount , 2 ) ;
1289
+ test . done ( ) ;
1262
1290
}
1263
1291
} ;
1264
1292
You can’t perform that action at this time.
0 commit comments