I have a file in an S3 bucket for which I would like to restrict access, so that it can only be accessed from within a specific Lambda function. I tried writing a Bucket policy (subbing in my info for region, account, etc.) to accomplish this:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1457474835965",
"Action": "s3:*",
"Principal": "*",
"Effect": "Deny",
"Resource": "arn:aws:s3:::my-bucket/file.txt",
"Condition": {
"ArnNotEquals": {
"aws:SourceArn": "arn:aws:lambda:region:account:function:FunctionName"
}
}
}
]
}
However access to the file was still denied to the Lambda function when it was invoked. How can I accomplish what I am trying to do?
Your lambda function will be running with a specific role. Create a policy that grants access to the s3 resource and add it to the role.
Example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::my-bucket/file.txt"
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With