Last active
October 25, 2018 10:32
-
-
Save deegloo/835084a3d19c33b9c128663c712b5738 to your computer and use it in GitHub Desktop.
Complete infrastructure for scheduling, notifying and triggering AWS Lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: >- | |
Schedule, notify and trigger it - the infrastructure. | |
Transform: "AWS::Serverless-2016-10-31" | |
Resources: | |
SNSTopic: | |
Type: AWS::SNS::Topic | |
DependsOn: HardWorkerLambda | |
Properties: | |
DisplayName: SNSTopic | |
TopicName: 'snstopic' | |
HardWorkerLambda: | |
Type: AWS::Serverless::Function | |
Properties: | |
FunctionName: 'hardworker' | |
Handler: index.handler | |
CodeUri: 's3://deegloo-blog-post/schedule-notify-trigger/hardworker.zip' | |
Runtime: nodejs6.10 | |
Policies: AmazonS3FullAccess | |
MemorySize: 1536 | |
Timeout: 300 | |
Environment: | |
Variables: | |
DATA_STORAGE_BUCKET_NAME: !Ref ProcessedDataBucket | |
HardWorkerLambdaSNSSubscription: | |
Type: AWS::SNS::Subscription | |
Properties: | |
Endpoint: !GetAtt HardWorkerLambda.Arn | |
Protocol: lambda | |
TopicArn: !Ref SNSTopic | |
HardWorkerLambdaInvokePermission: | |
Type: AWS::Lambda::Permission | |
Properties: | |
Action: lambda:InvokeFunction | |
Principal: sns.amazonaws.com | |
SourceArn: !Ref SNSTopic | |
FunctionName: !GetAtt HardWorkerLambda.Arn | |
NotifierLambda: | |
Type: AWS::Serverless::Function | |
DependsOn: SNSTopic | |
Properties: | |
FunctionName: 'notifier' | |
Handler: index.handler | |
CodeUri: 's3://deegloo-blog-post/schedule-notify-trigger/notifier.zip' | |
Runtime: nodejs6.10 | |
MemorySize: 1536 | |
Timeout: 300 | |
Environment: | |
Variables: | |
SNS_TOPIC_ARN: !Ref SNSTopic | |
NotifierLambdaScheduledRule: | |
Type: AWS::Events::Rule | |
Properties: | |
Name: 'notifier-scheduled-rule' | |
Description: 'Triggers notifier lambda once per day' | |
ScheduleExpression: cron(0 7 ? * * *) | |
State: ENABLED | |
Targets: | |
- | |
Arn: !GetAtt NotifierLambda.Arn | |
Id: TargetFunctionV1 | |
NotifierLambdaInvokePermission: | |
Type: AWS::Lambda::Permission | |
Properties: | |
FunctionName: !Ref NotifierLambda | |
Action: lambda:InvokeFunction | |
Principal: events.amazonaws.com | |
SourceArn: !GetAtt NotifierLambdaScheduledRule.Arn | |
ProcessedDataBucket: | |
Type: AWS::S3::Bucket | |
Properties: | |
BucketName: 'deegloo-processed-data' | |
PostProcessorLambda: | |
Type: AWS::Serverless::Function | |
Properties: | |
FunctionName: 'postprocessor' | |
Handler: index.handler | |
Policies: AmazonS3ReadOnlyAccess | |
Events: | |
ProcessedFileStoredEvent: | |
Type: S3 | |
Properties: | |
Bucket: !Ref ProcessedDataBucket | |
Events: s3:ObjectCreated:* | |
Filter: | |
S3Key: | |
Rules: | |
- Name: suffix | |
Value: '.json' | |
CodeUri: 's3://deegloo-blog-post/schedule-notify-trigger/postprocessor.zip' | |
Runtime: nodejs6.10 | |
MemorySize: 1536 | |
Timeout: 300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment