Search code examples
amazon-web-servicesaws-lambdaaws-sam

How can i add more policies to my Lambda if there is a Statement?


I added this under properties

        Statement:
          - Effect: Allow
            Action:
              - 'ses:SendEmail'
              - 'ses:SendRawEmail'
            Resource: '*'

It works, but i also want to add - AWSLambdaBasicExecutionRole but i get an error if i add it under Policies at the same level with Statement, before or after

Is there a way to have both?


Solution

  • Here is an example of an IAM role that includes specific SES permissions and also leverages the AWSLambdaBasicExecutionRole managed policy.

    MyLambdaRole:
      Type: AWS::IAM::Role
      Properties:
        AssumeRolePolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Principal:
                Service: lambda.amazonaws.com
              Action: sts:AssumeRole
        ManagedPolicyArns:
          - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
        Policies:
          - PolicyName: ses-access
            PolicyDocument:
              Statement:
                Effect: Allow
                Action:
                  - ses:SendEmail
                  - ses:SendRawEmail
                Resource: *