Search code examples
serverlessaws-serverlessaws-secrets-manager

Serverless offline not taking environment variables


I am new to serverless and would like your help to figure out what I am doing wrong. In my local development after using sls offline --config cusom.yml i am unable to retrieve secrets. After a bit of debugging, found out that the credentials is null.

However, when i invoke it separately using pure js aws-sdk (not with serverless) I am able to retrieve the secrets and the credentials is prepopulated. Please let me know if you have any suggestions on why this is not working with sls offline

enter image description here


Solution

  • Do you have the following files locally?

    ~/.aws/credentials
    ~/.aws/config
    

    These files serves as the credentials if you don't write them in your code. Most libraries and aws cli relies on them for access

    $ cat ~/.aws/credentials 
    [default]
    aws_secret_access_key = your_aws_secret_access_key
    aws_access_key_id = your_aws_access_key_id
    
    $ cat ~/.aws/config
    [default]
    region = us-east-1  # or your preferred region