Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 292 additions & 0 deletions src/patterns/__snapshots__/scheduled-lambda.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,297 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`The GuScheduledLambda pattern should create the correct resources with a cron schedule 1`] = `
{
"Metadata": {
"gu:cdk:constructs": [
"GuStack",
"GuDistributionBucketParameter",
"GuScheduledLambda",
],
"gu:cdk:version": "TEST",
},
"Parameters": {
"DistributionBucketName": {
"Default": "/account/services/artifact.bucket",
"Description": "SSM parameter containing the S3 bucket name holding distribution artifacts",
"Type": "AWS::SSM::Parameter::Value<String>",
},
},
"Resources": {
"mylambdafunction8D341B54": {
"DependsOn": [
"mylambdafunctionServiceRoleDefaultPolicy769897D4",
"mylambdafunctionServiceRoleE82C2E25",
],
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "DistributionBucketName",
},
"S3Key": "test-stack/TEST/testing/lambda.zip",
},
"Environment": {
"Variables": {
"APP": "testing",
"STACK": "test-stack",
"STAGE": "TEST",
},
},
"FunctionName": "my-lambda-function",
"Handler": "my-lambda/handler",
"LoggingConfig": {
"LogFormat": "JSON",
},
"MemorySize": 512,
"Role": {
"Fn::GetAtt": [
"mylambdafunctionServiceRoleE82C2E25",
"Arn",
],
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Key": "App",
"Value": "testing",
},
{
"Key": "gu:cdk:version",
"Value": "TEST",
},
{
"Key": "gu:repo",
"Value": "guardian/cdk",
},
{
"Key": "Stack",
"Value": "test-stack",
},
{
"Key": "Stage",
"Value": "TEST",
},
],
"Timeout": 30,
},
"Type": "AWS::Lambda::Function",
},
"mylambdafunctionServiceRoleDefaultPolicy769897D4": {
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:GetObject*",
"s3:GetBucket*",
"s3:List*",
],
"Effect": "Allow",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition",
},
":s3:::",
{
"Ref": "DistributionBucketName",
},
],
],
},
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition",
},
":s3:::",
{
"Ref": "DistributionBucketName",
},
"/test-stack/TEST/testing/lambda.zip",
],
],
},
],
},
{
"Action": "ssm:GetParametersByPath",
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ssm:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":parameter/TEST/test-stack/testing",
],
],
},
},
{
"Action": [
"ssm:GetParameters",
"ssm:GetParameter",
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ssm:",
{
"Ref": "AWS::Region",
},
":",
{
"Ref": "AWS::AccountId",
},
":parameter/TEST/test-stack/testing/*",
],
],
},
},
],
"Version": "2012-10-17",
},
"PolicyName": "mylambdafunctionServiceRoleDefaultPolicy769897D4",
"Roles": [
{
"Ref": "mylambdafunctionServiceRoleE82C2E25",
},
],
},
"Type": "AWS::IAM::Policy",
},
"mylambdafunctionServiceRoleE82C2E25": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com",
},
},
],
"Version": "2012-10-17",
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition",
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
],
],
},
],
"Tags": [
{
"Key": "App",
"Value": "testing",
},
{
"Key": "gu:cdk:version",
"Value": "TEST",
},
{
"Key": "gu:repo",
"Value": "guardian/cdk",
},
{
"Key": "Stack",
"Value": "test-stack",
},
{
"Key": "Stage",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
},
"mylambdafunctionmylambdafunctioncron08MONFRI0AllowEventRuleTestmylambdafunction4858F7ED0609698F": {
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"mylambdafunction8D341B54",
"Arn",
],
},
"Principal": "events.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"mylambdafunctionmylambdafunctioncron08MONFRI0CD5BC25F",
"Arn",
],
},
},
"Type": "AWS::Lambda::Permission",
},
"mylambdafunctionmylambdafunctioncron08MONFRI0CD5BC25F": {
"Properties": {
"ScheduleExpression": "cron(0 8 ? * MON-FRI *)",
"State": "ENABLED",
"Tags": [
{
"Key": "App",
"Value": "testing",
},
{
"Key": "gu:cdk:version",
"Value": "TEST",
},
{
"Key": "gu:repo",
"Value": "guardian/cdk",
},
{
"Key": "Stack",
"Value": "test-stack",
},
{
"Key": "Stage",
"Value": "TEST",
},
],
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"mylambdafunction8D341B54",
"Arn",
],
},
"Id": "Target0",
},
],
},
"Type": "AWS::Events::Rule",
},
},
}
`;

exports[`The GuScheduledLambda pattern should create the correct resources with an input in the rule 1`] = `
{
"Metadata": {
Expand Down
16 changes: 16 additions & 0 deletions src/patterns/scheduled-lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ describe("The GuScheduledLambda pattern", () => {
});
});

it("should create the correct resources with a cron schedule", () => {
const stack = simpleGuStackForTesting();
const noMonitoring: NoMonitoring = { noMonitoring: true };
const props = {
fileName: "lambda.zip",
functionName: "my-lambda-function",
handler: "my-lambda/handler",
runtime: Runtime.NODEJS_12_X,
rules: [{ schedule: Schedule.expression("cron(0 8 ? * MON-FRI *)") }],
monitoringConfiguration: noMonitoring,
app: "testing",
};
new GuScheduledLambda(stack, "my-lambda-function", props);
expect(Template.fromStack(stack).toJSON()).toMatchSnapshot();
});

it("should create the correct resources with an input in the rule", () => {
const stack = simpleGuStackForTesting();
const noMonitoring: NoMonitoring = { noMonitoring: true };
Expand Down
Loading