|
1 | 1 | import '@aws-cdk/assert/jest';
|
| 2 | +import { arrayWith } from '@aws-cdk/assert'; |
2 | 3 | import * as autoscaling from '@aws-cdk/aws-autoscaling';
|
3 | 4 | import * as ec2 from '@aws-cdk/aws-ec2';
|
| 5 | +import * as kms from '@aws-cdk/aws-kms'; |
4 | 6 | import * as lambda from '@aws-cdk/aws-lambda';
|
5 | 7 | import * as sns from '@aws-cdk/aws-sns';
|
6 | 8 | import * as sqs from '@aws-cdk/aws-sqs';
|
7 | 9 | import { Stack } from '@aws-cdk/core';
|
8 | 10 | import * as hooks from '../lib';
|
9 | 11 |
|
| 12 | + |
10 | 13 | describe('given an AutoScalingGroup', () => {
|
11 | 14 | let stack: Stack;
|
12 | 15 | let asg: autoscaling.AutoScalingGroup;
|
@@ -77,4 +80,47 @@ describe('given an AutoScalingGroup', () => {
|
77 | 80 | Endpoint: { 'Fn::GetAtt': [ 'Fn9270CBC0', 'Arn' ] },
|
78 | 81 | });
|
79 | 82 | });
|
| 83 | + |
| 84 | + test('can use Lambda function as hook target with encrypted SNS', () => { |
| 85 | + // GIVEN |
| 86 | + const key = new kms.Key(stack, 'key'); |
| 87 | + const fn = new lambda.Function(stack, 'Fn', { |
| 88 | + code: lambda.Code.fromInline('foo'), |
| 89 | + runtime: lambda.Runtime.NODEJS_10_X, |
| 90 | + handler: 'index.index', |
| 91 | + }); |
| 92 | + |
| 93 | + // WHEN |
| 94 | + asg.addLifecycleHook('Trans', { |
| 95 | + lifecycleTransition: autoscaling.LifecycleTransition.INSTANCE_LAUNCHING, |
| 96 | + notificationTarget: new hooks.FunctionHook(fn, key), |
| 97 | + }); |
| 98 | + |
| 99 | + // THEN |
| 100 | + expect(stack).toHaveResourceLike('AWS::SNS::Topic', { |
| 101 | + KmsMasterKeyId: { |
| 102 | + Ref: 'keyFEDD6EC0', |
| 103 | + }, |
| 104 | + }); |
| 105 | + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { |
| 106 | + PolicyDocument: { |
| 107 | + Statement: arrayWith( |
| 108 | + { |
| 109 | + Effect: 'Allow', |
| 110 | + Action: [ |
| 111 | + 'kms:Decrypt', |
| 112 | + 'kms:GenerateDataKey', |
| 113 | + ], |
| 114 | + Resource: { |
| 115 | + 'Fn::GetAtt': [ |
| 116 | + 'keyFEDD6EC0', |
| 117 | + 'Arn', |
| 118 | + ], |
| 119 | + }, |
| 120 | + }, |
| 121 | + ), |
| 122 | + }, |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
80 | 126 | });
|
0 commit comments