I’m not an AWS expert, so I need some help configuring access policies to a S3 Bucket audio file.
Quick explain:
I’m trying to call a lambda function and access a audio file from a S3 bucket with private access. My lambda function (same aws account) should be able to access the mp3 file through its URI.
Details:
I’m developing an Alexa Skill in .NET hosted on AWS Lambda. This skill needs to play an audio that will be retrieved from a S3 Bucket.
The only way I was able to play the audio was leaving the mp3 file accessible for everyone (allow public access), but I want to restrict the access for my lambda function (same aws account) only. In other words: I don’t want anyone can access these files, just my lambda function.
Whenever I configure the access policy, the alexa skill doesn’t access the file anymore and returns: "It was not possible to stablish a connection with the provided audio file URI"
I tried:
- Creating a role on IAM management console
- Creating a inline policy and attaching all S3 list and read permissions for any resource
- Setting up the created role to my lambda function execution role
But it’s not working.
Anyone knows how to configure it correctly?
Reference:lambda-execution-role-s3-bucket
2
Answers
What @Anon Coward suggested worked fine!
I wasn't realizing that when I provide the URI to Alexa through REST API it isn't going to be resolved on my own function. For this reason Alexa didn't have access to any file. Thanks you all!
You should create an IAM Role and associate that IAM Role with the AWS Lambda function.
The IAM Role should have the following permissions:
AWSLambdaBasicExecutionRole
managed policy, which gives permission for the Lambda function to send logging to CloudWatch Logs (See Lambda execution role – AWS Lambda)This policy gives the Lambda function permission to list the contents of the bucket, and upload/download/delete objects from the bucket.
If you merely want the Lambda function to read files in the bucket, you can reduce it to: