Skip to content

Commit 6136d9e

Browse files
authored
chore(scheduler-alpha): unit test schedule with Lambda version as target (#31872)
### Issue # (if applicable) None. ### Reason for this change Missing this test case. ### Description of changes Adding a unit test to verify `Schedule` works with Lambda Version and correct permissions are added. ### Description of how you validated changes Unit test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8d06824 commit 6136d9e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,63 @@ describe('schedule target', () => {
8585
});
8686
});
8787

88+
test('creates IAM role and IAM policy for lambda version', () => {
89+
const lambdaVersion = new lambda.Version(stack, 'MyLambdaVersion', {
90+
lambda: func,
91+
});
92+
const lambdaTarget = new LambdaInvoke(lambdaVersion, {});
93+
94+
new Schedule(stack, 'MyScheduleDummy', {
95+
schedule: expr,
96+
target: lambdaTarget,
97+
});
98+
99+
Template.fromStack(stack).resourceCountIs('AWS::Lambda::Permission', 0);
100+
101+
Template.fromStack(stack).hasResource('AWS::Scheduler::Schedule', {
102+
Properties: {
103+
Target: {
104+
Arn: {
105+
Ref: 'MyLambdaVersion2EF97E33',
106+
},
107+
RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] },
108+
RetryPolicy: {},
109+
},
110+
},
111+
});
112+
113+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
114+
PolicyDocument: {
115+
Statement: [
116+
{
117+
Action: 'lambda:InvokeFunction',
118+
Effect: 'Allow',
119+
Resource: {
120+
Ref: 'MyLambdaVersion2EF97E33',
121+
},
122+
},
123+
],
124+
},
125+
Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }],
126+
});
127+
128+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
129+
AssumeRolePolicyDocument: {
130+
Version: '2012-10-17',
131+
Statement: [
132+
{
133+
Effect: 'Allow',
134+
Condition: { StringEquals: { 'aws:SourceAccount': '123456789012' } },
135+
Principal: {
136+
Service: 'scheduler.amazonaws.com',
137+
},
138+
Action: 'sts:AssumeRole',
139+
},
140+
],
141+
},
142+
});
143+
});
144+
88145
test('creates IAM policy for provided IAM role', () => {
89146
const targetExecutionRole = new Role(stack, 'ProvidedTargetRole', {
90147
assumedBy: new AccountRootPrincipal(),

0 commit comments

Comments
 (0)