Serverless deployement giving access denied and forbidden on writing and reading an s3 bucket respectively

0

I have an api which takes a file from user and uploads it to s3. I am using my IAM access and secret to configure the s3 client. I have turned off all public access in my bucket and am using default permissions. In my local machine, I am able to read and write objects in the bucket successfully but when I am deploying it to a lambda using serverless, and checking the api it is giving error access denied for writing and Forbidden: null for reading. I have checked my environment variables and they seem correct. I don't understand why it is not working on Serverless if it is working locally.

1개 답변
1

Hi,

When running in Lambda, you don't want to use env var for access keys and secret keys: it is a bad practice.

You rather want to use the Lambda execution role and grant it the service credentials needed by your use case: https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html

This article explains very well how to use the execution role: https://medium.com/aws-lambda-serverless-developer-guide-with-hands/aws-lambda-permissions-execution-role-and-resource-based-policies-be2e325998fc

Best,

Didier

profile pictureAWS
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠