Skip to content

Commit

Permalink
better logical names, updating changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
bilindhajer committed Feb 7, 2024
1 parent 034cb62 commit 9676ef7
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 31 deletions.
10 changes: 6 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
- Updates `cf.shortcuts.ScheduledLambda` to use EventBridge Scheduler instead of EventBridge Rules to schedule lambda invocations. When using this version your template will have the following changes per scheduled lambda instance,

```
Add AWS::IAM::Role
Add AWS::Scheduler::Schedule
Remove AWS::Lambda::Permission
Remove AWS::Events::Rule
Add <LogicalNamePrefix>SchedulerRole AWS::IAM::Role
Add <LogicalNamePrefix>Scheduler AWS::Scheduler::Schedule
Remove <LogicalNamePrefix>Permission AWS::Lambda::Permission
Remove <LogicalNamePrefix>Schedule AWS::Events::Rule
```

Note the service role (`AWS::IAM::Role`) will automatically be created for the `AWS::Scheduler::Schedule` resource if you do not specify property `ScheduleRoleArn` in the shortcut.

When you make this update, you will no longer see a trigger on your scheduled lambda. The schedule can be viewed in EventBridge schedules.

- [Read more in API reference doc](./lib/shortcuts/api.md#ScheduledLambda)
- [Read more about the EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-group.html)

Expand Down
10 changes: 5 additions & 5 deletions lib/shortcuts/scheduled-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ScheduledLambda extends Lambda {
if (required.some((variable) => !variable))
throw new Error('You must provide a ScheduleExpression');

this.Resources[`${this.LogicalName}EventBridgeSchedule`] = {
this.Resources[`${this.LogicalName}Scheduler`] = {
Type: 'AWS::Scheduler::Schedule',
Condition: this.Condition,
Properties: {
Expand All @@ -101,14 +101,14 @@ class ScheduledLambda extends Lambda {
};

if (ScheduleGroupName) {
this.Resources[`${this.LogicalName}EventBridgeSchedule`].Properties.GroupName = ScheduleGroupName;
this.Resources[`${this.LogicalName}Scheduler`].Properties.GroupName = ScheduleGroupName;
}

if (ScheduleRoleArn) {
this.Resources[`${this.LogicalName}EventBridgeSchedule`].Properties.Target.RoleArn = ScheduleRoleArn;
this.Resources[`${this.LogicalName}Scheduler`].Properties.Target.RoleArn = ScheduleRoleArn;
} else {
const serviceRole = new ServiceRole({
LogicalName: `${this.LogicalName}EventBridgeScheduleRole`,
LogicalName: `${this.LogicalName}SchedulerRole`,
Service: 'scheduler.amazonaws.com',
Condition: this.Condition,
Statement: [
Expand All @@ -121,7 +121,7 @@ class ScheduledLambda extends Lambda {
}
]
});
this.Resources[`${this.LogicalName}EventBridgeSchedule`].Properties.Target.RoleArn = { 'Fn::GetAtt': [`${this.LogicalName}EventBridgeScheduleRole`, 'Arn'] };
this.Resources[`${this.LogicalName}Scheduler`].Properties.Target.RoleArn = { 'Fn::GetAtt': [`${this.LogicalName}EventBridgeScheduleRole`, 'Arn'] };
this.Resources = merge(this, serviceRole).Resources;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-github-secret-ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -47,7 +47,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-github-secret-string.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-github.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand Down Expand Up @@ -52,7 +52,7 @@
}
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-passthrough-alarms.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-passthrough-logging.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-passthrough.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeployment73cfb54f"
"Ref": "PassDeploymentd5673243"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeployment73cfb54f": {
"PassDeploymentd5673243": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/scheduled-lambda-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}
}
},
"MyLambdaEventBridgeSchedule": {
"MyLambdaScheduler": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"Name": {
Expand Down Expand Up @@ -165,7 +165,7 @@
}
}
},
"MyLambdaEventBridgeScheduleRole": {
"MyLambdaSchedulerRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/scheduled-lambda-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}
}
},
"MyLambdaEventBridgeSchedule": {
"MyLambdaScheduler": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"Name": {
Expand Down Expand Up @@ -166,7 +166,7 @@
"GroupName": "my-cool-stack"
}
},
"MyLambdaEventBridgeScheduleRole": {
"MyLambdaSchedulerRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down

0 comments on commit 9676ef7

Please sign in to comment.