While I have been using the serverless framework since it’s inception, I am trying out components for the first time this weekend.
I work with numerous clients and have my IAM credentials for each configured in ~/.aws/credentials. This has always worked well for SLS Lambda functions as I can deploy with sls deploy --aws-profile {profile-name}
as documented in Serverless Framework - AWS Credentials.
However, when I try the same for deploying a component I get
Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken
Does Serverless component deployment support AWS profiles? Or do I have to add my secret and key to an .env file? As long as I remember to add .env to .gitignore it should be safe, but the risk is still greater than using the AWS profile. I also have built up over time a series of bash scripts for automating my flow that make heavy use of profiles. It would be a shame to have to start rewriting those just so I can use Serverless components.
Yes you can, assuming you are on mac or linux you can set the AWS_PROFILE environment variable
AWS_PROFILE=profile-name sls deploy
Thanks @apsoto_wurl but unfortunately that’s not quite what I was asking. Both the AWS CLI and SLS CLI (for functions) allow the profile to be set using a --profile
flag. Since we switch between so many client accounts throughout the day we have built a bash framework around a lot of the common task, and that framework expects and passes the --profile flag. For some reason Serverless component management does not accept that flag.
@tforster ok, I recall trying --profile and it not working, so my example above is what I figured out as my work around.
Good luck, and please post back if you find a way for it to work.
This bug(?) just bit me again. I have been deploying with sls --aws-profile {profilename}
and banging my head against the wall wondering why SLS says it’s successful and I cannot find anything in my client’s account. Then, when I go to my personal account I see all my client work there. Serverless is still ignoring --aws-profile
for serverless components.
This worked for me.
AWS_PROFILE=personal sls deploy -s dev
@trevorallred That works but the issue is that when the serverless framework first launched, before they introduced components, they supported --aws-profile {profile-name}
. But for some reason did not carry it over to components. It’s still part of the sls
command for any non-component CLI functions. I use it all the time and I have extensive scripts set up to use it across clients. I just wish I could use it when working with Serverless Framework components.
I was facing the same issue
" AWS_PROFILE=personal sls deploy -s dev "
it worked for me
AWS Classes in Pune