If you’ve worked with AWS Serverless templates, you’ll appreciate how quickly you can deploy a raft of infrastructure with very little template code. The only flaw I’ve found so far is the documentation is a bit tricky to find.
Say you want to attach some custom policies to your function, you can simply embed them into your template. E.g:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
{ "AWSTemplateFormatVersion": "2010-09-09", "Transform": "AWS::Serverless-2016-10-31", "Description": "An AWS Serverless Application.", "Resources": { "BackupTriggerGeneratorFunction": { "Type": "AWS::Serverless::Function", "Properties": { "Handler": "BackupTriggerGenerator::BackupTriggerGenerator.Functions::FunctionHandler", "Runtime": "dotnetcore2.0", "CodeUri": "", "MemorySize": 256, "Timeout": 30, "Environment": { "Variables": { "BucketName": "...", "FolderNames": "...", "FileName": "..." } }, "Role": null, "Policies": [ "AWSLambdaBasicExecutionRole", "AmazonS3ReadOnlyAccess", { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:Put*" ], "Resource": [ "arn:aws:s3:::bucketname-*-*-*-1/Databases/*" ] } ] } ], "Events": { "Schedule": { "Type": "Schedule", "Properties": { "Schedule": "cron(30 1,3,5,7,9,11,13,15,17,19,21,23 * * ? *)" } } } } } } } |
This also shows a few other neat features:
- Wildcards in the custom policy name, allowing it to work across multiple buckets
- Cron triggered events
- How to set environment variables from your template