Description
To run a Lambda function on an S3 event, allow S3 to perform lambda:InvokeFunction in the function’s resource policy.
Potential impact
A grant for lambda:GetFunction alone cannot deliver the event to the function.
Remediation
In AWS::Lambda::Permission, set Principal to S3 and limit SourceArn and SourceAccount to the bucket and its owner. Configure the bucket notification and verify that an event reaches the function.
Examples
Both excerpts reference the same function and bucket. The second changes only Action, retaining the caller and source conditions.
Before
yaml
Resources:
s3Permission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt function.Arn
Action: lambda:GetFunction
Principal: s3.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt bucket.Arn
After
yaml
Resources:
s3Permission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt function.Arn
Action: lambda:InvokeFunction
Principal: s3.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
SourceArn: !GetAtt bucket.Arn