Search code examples
amazon-web-servicesenvironment-variablesgithub-actionsfastapisam

How to get s3 env files in aws sam with github action


These days I research SAM(Serverless Application Model) to deploy my fastapi sample. However, I can't get the s3 env file. The sam cli command is below.

$ sam build --use-container
$ sam deploy

The point of error in the code is below.

content_object = boto3.resource('s3').Object('config', 'test.json')

In the local env, I can get the env file in the s3 bucket, but when I deploy with sam, the error has occurred like this.

[ERROR] ClientError: An error occurred (AccessDenied) when calling the GetObject operation: Access Denied

How to solve this issue? Have any good sources for getting env files in SAM? I just want to make deploy in github action.


Solution

  • I have an issue that loads an env file with SAM (AWS Serverless Application Model) application(FastAPI). However, I can't load the env file in the python script since SAM env is different from Zappa (Zappa can env file with remote_env in the config file). So, I use the copy method in the GitHub action (workflow).