|
1 | 1 | import { countResources, expect, haveResource } from '@aws-cdk/assert';
|
2 | 2 | import cloudfront = require('@aws-cdk/aws-cloudfront');
|
| 3 | +import iam = require('@aws-cdk/aws-iam'); |
3 | 4 | import s3 = require('@aws-cdk/aws-s3');
|
4 | 5 | import cdk = require('@aws-cdk/core');
|
5 | 6 | import { Test } from 'nodeunit';
|
@@ -234,7 +235,7 @@ export = {
|
234 | 235 | s3OriginSource: {
|
235 | 236 | s3BucketSource: bucket
|
236 | 237 | },
|
237 |
| - behaviors : [ {isDefaultBehavior: true}] |
| 238 | + behaviors: [{ isDefaultBehavior: true }] |
238 | 239 | }
|
239 | 240 | ]
|
240 | 241 | });
|
@@ -267,7 +268,7 @@ export = {
|
267 | 268 | s3OriginSource: {
|
268 | 269 | s3BucketSource: bucket
|
269 | 270 | },
|
270 |
| - behaviors : [ {isDefaultBehavior: true}] |
| 271 | + behaviors: [{ isDefaultBehavior: true }] |
271 | 272 | }
|
272 | 273 | ]
|
273 | 274 | });
|
@@ -427,8 +428,38 @@ export = {
|
427 | 428 | // we expect to find only two handlers, one for each configuration
|
428 | 429 |
|
429 | 430 | expect(stack).to(countResources('AWS::Lambda::Function', 2));
|
430 |
| - expect(stack).to(haveResource('AWS::Lambda::Function', { MemorySize: 256 })); |
| 431 | + expect(stack).to(haveResource('AWS::Lambda::Function', { MemorySize: 256 })); |
431 | 432 | expect(stack).to(haveResource('AWS::Lambda::Function', { MemorySize: 1024 }));
|
432 | 433 | test.done();
|
| 434 | + }, |
| 435 | + |
| 436 | + 'deployment allows custom role to be supplied'(test: Test) { |
| 437 | + |
| 438 | + // GIVEN |
| 439 | + const stack = new cdk.Stack(); |
| 440 | + const bucket = new s3.Bucket(stack, 'Dest'); |
| 441 | + const existingRole = new iam.Role(stack, 'Role', { |
| 442 | + assumedBy: new iam.ServicePrincipal('lambda.amazon.com') |
| 443 | + }); |
| 444 | + |
| 445 | + // WHEN |
| 446 | + new s3deploy.BucketDeployment(stack, 'DeployWithRole', { |
| 447 | + sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))], |
| 448 | + destinationBucket: bucket, |
| 449 | + role: existingRole |
| 450 | + }); |
| 451 | + |
| 452 | + // THEN |
| 453 | + expect(stack).to(countResources('AWS::IAM::Role', 1)); |
| 454 | + expect(stack).to(countResources('AWS::Lambda::Function', 1)); |
| 455 | + expect(stack).to(haveResource('AWS::Lambda::Function', { |
| 456 | + "Role": { |
| 457 | + "Fn::GetAtt": [ |
| 458 | + "Role1ABCC5F0", |
| 459 | + "Arn" |
| 460 | + ] |
| 461 | + } |
| 462 | + })); |
| 463 | + test.done(); |
433 | 464 | }
|
434 | 465 | };
|
0 commit comments