Framework is ignoring profile (AWS account) settings (per stage profile)


I want Serverless Framework to deploy stack to 2 different AWS accounts depending on stage.

My .aws\credentials looks like that:

aws_access_key_id = AKI....
aws_secret_access_key = Lwx....
aws_access_key_id = AKI...
aws_secret_access_key = 7pjV....
aws_access_key_id = AK....
aws_secret_access_key = Lw....

and my serverless.yml looks like that:

  myStage: ${opt:stage, self:provider.stage}
    dev: testAccount
    prod: prodAccount
    dev: eu-west-1 # Ireland
    prod: us-west-2 # Oregon

  name: aws
  stage: dev
  runtime: nodejs8.10
  profile: ${self:custom.myProfile.${self:custom.myStage}}
  region: ${self:custom.myRegion.${self:custom.myStage}}

Both sls deploy --stage prod & sls deploy commend deploy stack to the [default] account.

I saw similar config in docs

What am I doing wrong?

PS. What’s also strange is that regions are properly handled.

sls -v

I think you need to set an environment varable called “AWS_PROFILE” [1][2].
This should help the aws cli to use the profile you want.



@willKo I don’t think so. It used to work without environment varable correctly.


@Pawel I am having the same issue. Tried removing serverless and reinstalling but same issue (specifying an an aws profile, but deploying to my main aws account)


I deploy to two different stacks without any problems, but I do have a slightly different setup:

  ${file(env/${opt:stage, 'dev'}.yml)}

  profile: ${self:custom.profile}

In dev.yml I have

profile: "dev"

And in prd.yml I have

profile: "prd"

Obviously my default and prd profiles are set up in point to separate accounts in .aws/credentials


@Pawel my issue ended up being that I was looking for them in the aws web gui, but was looking in the wrong region :man_facepalming:


The way how we work in our environment is we do not hard code the stage or region in the serverless.yml file. It is passed via the deploy command.

Command line to deploy :

serverless deploy --stage dev --region us-east-1 --profile awsDev

Sample Serverless.yml File

service: xyz

  name: aws
  runtime: nodejs6.10
  memorySize: 1024
    XXX: ${ssm:/${self:custom.stage}/xxx~true}
  stage: ${opt:stage, self:provider.stage}
    onError: ${self:provider.environment.XXX}
    access: public
      - http:
          path : myApi
          method : get

@Pawel did you find a fix?