From ffb6a033939ae57158032200a26760a141489fa5 Mon Sep 17 00:00:00 2001 From: Warrick Zedi Date: Fri, 2 Feb 2018 08:15:17 +1100 Subject: [PATCH 1/2] Added serverless service config to deploy Lambda function and S3 backup bucket --- .gitignore | 1 + serverless.yml | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 serverless.yml diff --git a/.gitignore b/.gitignore index fd4f2b0..59d37e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules .DS_Store +.serverless diff --git a/serverless.yml b/serverless.yml new file mode 100644 index 0000000..ac22a2f --- /dev/null +++ b/serverless.yml @@ -0,0 +1,61 @@ +service: dynamodb-backup +frameworkVersion: "=1.26.0" + +provider: + name: aws + runtime: nodejs6.10 + region: ap-southeast-2 + + iamRoleStatements: + - Effect: "Allow" + Action: + - "logs:CreateLogGroup" + - "logs:CreateLogStream" + - "logs:PutLogEvents" + Resource: "arn:aws:logs:*:*:*" + - Effect: "Allow" + Action: + - "s3:ListBucket" + Resource: "arn:aws:s3:::orchestrated-test-dynamodb-backup" + - Effect: "Allow" + Action: + - "s3:GetObject" + - "s3:PutObject" + - "s3:DeleteObject" + Resource: "arn:aws:s3:::orchestrated-test-dynamodb-backup/*" + - Effect: "Allow" + Action: "lambda:InvokeFunction" + Resource: "*" + - Effect: "Allow" + Action: + - "dynamodb:DescribeStream" + - "dynamodb:GetRecords" + - "dynamodb:GetShardIterator" + - "dynamodb:ListStreams" + Resource: "*" + +package: + include: + - ./*.js + - ./node_modules + +functions: + index: + handler: index.backup + + events: + - stream: arn:aws:dynamodb:ap-southeast-2:619797987959:table/BackupTest/stream/2018-02-01T05:14:27.659 + + environment: + BackupRegion: ap-southeast-2 + BackupBucket: orchestrated-test-dynamodb-backup + BackupPrefix: test + +resources: + Resources: + BackupBucket: + Type: AWS::S3::Bucket + Properties: + BucketName: orchestrated-test-dynamodb-backup + VersioningConfiguration: + Status: "Enabled" From c1a70fc195a653218a107e734e6b96dde08c9eaa Mon Sep 17 00:00:00 2001 From: Warrick Zedi Date: Fri, 2 Feb 2018 08:31:43 +1100 Subject: [PATCH 2/2] Removed AWS resource names and ARNS and replaced with placeholders --- serverless.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/serverless.yml b/serverless.yml index ac22a2f..b920ce3 100644 --- a/serverless.yml +++ b/serverless.yml @@ -16,13 +16,13 @@ provider: - Effect: "Allow" Action: - "s3:ListBucket" - Resource: "arn:aws:s3:::orchestrated-test-dynamodb-backup" + Resource: "" - Effect: "Allow" Action: - "s3:GetObject" - "s3:PutObject" - "s3:DeleteObject" - Resource: "arn:aws:s3:::orchestrated-test-dynamodb-backup/*" + Resource: "arn:aws:s3:::/*" - Effect: "Allow" Action: "lambda:InvokeFunction" Resource: "*" @@ -44,18 +44,18 @@ functions: handler: index.backup events: - - stream: arn:aws:dynamodb:ap-southeast-2:619797987959:table/BackupTest/stream/2018-02-01T05:14:27.659 + - stream: environment: - BackupRegion: ap-southeast-2 - BackupBucket: orchestrated-test-dynamodb-backup - BackupPrefix: test + BackupRegion: + BackupBucket: + BackupPrefix: resources: Resources: BackupBucket: Type: AWS::S3::Bucket Properties: - BucketName: orchestrated-test-dynamodb-backup + BucketName: VersioningConfiguration: Status: "Enabled"