Search code examples
amazon-web-servicesaws-serverlessaws-samaws-policies

Does S3WritePolicy allow multiple buckets in AWS SAM template?


After reading S3WritePolicy documentation, it's not clear if it allows multiple buckets.

I'm currently doing this:

SampleLambdaFunction:
  Type: AWS::Serverless::Function
  Properties:
    Policies:
      - S3WritePolicy:
          BucketName: bucket-1

but if I wanted to include multiple buckets, i.e.:

SampleLambdaFunction:
  Type: AWS::Serverless::Function
  Properties:
    Policies:
      - S3WritePolicy:
          BucketName: 
             - bucket-1
             - bucket-2

would this be allowed?


Solution

  • Does S3WritePolicy allow multiple buckets in AWS SAM template?

    Yes.

    would this be allowed?

    No, but the below would be allowed.

    This is because it's a SAM policy template & is essentially generating a policy for a single bucket. You can however use it as many times as needed.

    SampleLambdaFunction:
      Type: AWS::Serverless::Function
      Properties:
        Policies:
          - S3WritePolicy:
              BucketName: 
                 - bucket-1
          - S3WritePolicy:
              BucketName: 
                 - bucket-2