I have an AWS Lambda Function that accesses an S3 resource by it’s URL (i.e https://s3-eu-west-1.amazonaws.com/bucketname/key).
I have added a Bucket Policy on the S3 Bucket that allows my Lambda Function access to the S3 Bucket (via the Lambda Functions IAM Role). This Bucket Policy looks as follows:
{
"Version": "2012-10-17",
"Id": "Access control to S3 bucket",
"Statement": [
{
"Sid": "Allow Get and List Requests from IAM Role",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123412341234:role/role-name“
},
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::bucket-name”,
"arn:aws:s3:::bucket-name/*"
]
}
]
}
This all works fine when the Lambda Function is activated "automatically" by an trigger. But when I test the Lambda Function manually (via the AWS Console) I get a 403 error.
If I then change the Principal in the S3 Bucket Policy to “*” the 403 exception is resolved.
My guess is that a different Principal is used when manually triggering the Lambda Function, but I’ve no idea what this might be. I’ve tried adding a new policy giving access to my canonical user but this doesn’t work.
Any suggestions?