AWS Config + Credentials

I would like to use aws-cli’s config and credentials files as env variables in my serverless.yml file but can’t seem to find documentation on how this is done.

Ideally I have profiles for different environments (prod vs dev) where I have 2 different AWS accounts to split dev/staging away from production environments.

The best I can tell is that serverless will grab profile’s aws access key and secret just for running deploy but doesn’t load profile config data as environment variables…

You can pass in a profile like so:

serverless config credentials --provider aws --key 1234 --secret 5678 --profile custom-profile

For more details check the Serverless Framework docs.

Thanks,
Rupak Ganguly

yeah, after running through that, it doesn’t consider .aws/config.
But if using --aws-profile, does that set an env variable anywhere that can be used in the serverless.yml file?

If you want to use .aws/config, You should make sure that .aws/config id is different from .aws/credentials id.

ex).

// .aws/config
[default]
region = ap-northeast-2

[test]
role_arn = **
region = **
// .aws/credentials
[default]
aws_access_key_id = YOUR_KEY_ID
aws_secret_access_key = YOUR_SECRET_KEY

[test]
aws_access_key_id = TEST_KEY_ID
aws_secret_access_key = TEST_SECRET_KEY

If you execute some command like sls invoke -f test-function --aws-profile test in this situation,
Then the serverless-cli considers only .aws/credentials.
I think the serverless-cli considers .aws/credentials first.
Try again after remove the same id in the .aws/credentials.