From 51452f40ac39594c2ffb0cd0c140238f098784a3 Mon Sep 17 00:00:00 2001 From: Tim Ryan Date: Mon, 22 Oct 2018 13:32:44 -0400 Subject: [PATCH] Fix issues where example lambdas don't have permissions for s3 buckets s3 Buckets and lambdas were being generated but lambda didn't have permissions for s3 buckets. Started using prefix and Sub to intrinsically tie them together to circumvent circular dependency issues. --- examples/apps/rekognition-python/template.yaml | 7 +++++-- examples/apps/s3-get-object-python/template.yaml | 7 +++++-- examples/apps/s3-get-object-python3/template.yaml | 7 +++++-- examples/apps/s3-get-object/template.yaml | 10 ++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/apps/rekognition-python/template.yaml b/examples/apps/rekognition-python/template.yaml index 36a2b50de..93e7930c5 100644 --- a/examples/apps/rekognition-python/template.yaml +++ b/examples/apps/rekognition-python/template.yaml @@ -2,8 +2,9 @@ AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' Description: An Amazon S3 trigger that uses rekognition APIs to detect faces Parameters: - BucketNameParameter: + BucketNamePrefix: Type: String + Default: sam-example CollectionIdParameter: Type: String Resources: @@ -18,7 +19,7 @@ Resources: Timeout: 3 Policies: - S3CrudPolicy: - BucketName: !Ref BucketNameParameter + BucketName: !Sub "${BucketNamePrefix}-rekognition" - RekognitionNoDataAccessPolicy: CollectionId: !Ref CollectionIdParameter - RekognitionWriteOnlyAccessPolicy: @@ -33,3 +34,5 @@ Resources: - 's3:ObjectCreated:*' Bucket1: Type: 'AWS::S3::Bucket' + Properties: + BucketName: !Sub "${BucketNamePrefix}-rekognition" diff --git a/examples/apps/s3-get-object-python/template.yaml b/examples/apps/s3-get-object-python/template.yaml index 376f9e736..7860ececc 100644 --- a/examples/apps/s3-get-object-python/template.yaml +++ b/examples/apps/s3-get-object-python/template.yaml @@ -4,8 +4,9 @@ Description: >- An Amazon S3 trigger that retrieves metadata for the object that has been updated. Parameters: - BucketNameParameter: + BucketNamePrefix: Type: String + Default: sam-example Resources: s3getobjectpython: Type: 'AWS::Serverless::Function' @@ -20,7 +21,7 @@ Resources: Timeout: 3 Policies: - S3CrudPolicy: - BucketName: !Ref BucketNameParameter + BucketName: !Sub "${BucketNamePrefix}-get-object-python" Events: BucketEvent1: Type: S3 @@ -31,3 +32,5 @@ Resources: - 's3:ObjectCreated:*' Bucket1: Type: 'AWS::S3::Bucket' + Properties: + BucketName: !Sub "${BucketNamePrefix}-get-object-python" diff --git a/examples/apps/s3-get-object-python3/template.yaml b/examples/apps/s3-get-object-python3/template.yaml index d6284d941..09dcf6218 100644 --- a/examples/apps/s3-get-object-python3/template.yaml +++ b/examples/apps/s3-get-object-python3/template.yaml @@ -4,8 +4,9 @@ Description: >- An Amazon S3 trigger that retrieves metadata for the object that has been updated. Parameters: - BucketNameParameter: + BucketNamePrefix: Type: String + Default: sam-example Resources: s3getobjectpython3: Type: 'AWS::Serverless::Function' @@ -20,7 +21,7 @@ Resources: Timeout: 3 Policies: - S3CrudPolicy: - BucketName: !Ref BucketNameParameter + BucketName: !Sub "${BucketNamePrefix}-get-object-python3" Events: BucketEvent1: Type: S3 @@ -31,3 +32,5 @@ Resources: - 's3:ObjectCreated:*' Bucket1: Type: 'AWS::S3::Bucket' + Properties: + BucketName: !Sub "${BucketNamePrefix}-get-object-python3" diff --git a/examples/apps/s3-get-object/template.yaml b/examples/apps/s3-get-object/template.yaml index 7743cbc25..9a813e419 100644 --- a/examples/apps/s3-get-object/template.yaml +++ b/examples/apps/s3-get-object/template.yaml @@ -4,8 +4,9 @@ Description: >- An Amazon S3 trigger that retrieves metadata for the object that has been updated. Parameters: - BucketNameParameter: + BucketNamePrefix: Type: String + Default: sam-example Resources: s3getobject: Type: 'AWS::Serverless::Function' @@ -20,14 +21,15 @@ Resources: Timeout: 3 Policies: - S3CrudPolicy: - BucketName: !Ref BucketNameParameter + BucketName: !Sub "${BucketNamePrefix}-get-object" Events: BucketEvent1: Type: S3 Properties: - Bucket: - Ref: Bucket1 + Bucket: !Ref Bucket1 Events: - 's3:ObjectCreated:*' Bucket1: Type: 'AWS::S3::Bucket' + Properties: + BucketName: !Sub "${BucketNamePrefix}-get-object"