2

I have the following circle ci template that I use from a tutorial.


jobs:
  create_infrastructure:
    docker:
      - image: amazon/aws-cli
    steps:
      - checkout
      - run:
          name: Ensure backend infrastructure exist
          command: |
            aws cloudformation deploy \
              --template-file template.yml \
              --stack-name my-stack
workflows:
  my_workflow:
    jobs:
      - create_infrastructure

But when I execute in in circle ci, I get

You must specify a region. You can also configure your region by running "aws configure".

Exited with code exit status 253

Please help me troubleshoot. enter image description here

Also tried adding the env vars to circleci like in the screenshot enter image description here

vprocopan
  • 53
  • 7
  • Does this answer your question? [Error You must specify a region when running command aws ecs list-container-instances](https://stackoverflow.com/questions/29166957/error-you-must-specify-a-region-when-running-command-aws-ecs-list-container-inst). You need to pass the region name as an environment variable or flag as indicated in the link – Sathyajith Bhat Feb 22 '21 at 06:16
  • It seems that these configurations don't work – vprocopan Feb 22 '21 at 07:35

1 Answers1

1

As the error message suggests. You need to add region to your config:

jobs:
  create_infrastructure:
    docker:
      - image: amazon/aws-cli
    steps:
      - checkout
      - run:
          name: Ensure backend infrastructure exist
          command: |
            aws cloudformation deploy \
              --template-file template.yml \
              --stack-name my-stack \
              --region <your-region, e.g. us-east-1>
workflows:
  my_workflow:
    jobs:
      - create_infrastructure

Update

Using the command in one line, as opposed multi-line, was the solution:

aws cloudformation deploy --template-file template.yml --stack-name my-stack --region eu-central-1
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • i've committed: ``` aws cloudformation deploy \ --template-file template.yml \ --stack-name my-stack --region eu-central-1 ``` But I still get ``` #!/bin/bash -eo pipefail aws cloudformation deploy \ --template-file template.yml \ --stack-name my-stack --region eu-central-1 You must specify a region. You can also configure your region by running "aws configure". Exited with code exit status 253 CircleCI received exit code 253 ``` – vprocopan Feb 22 '21 at 06:47
  • to add to that i did aws configure on the VM i run commits, maybe I need to set it somewhere in circleci ? – vprocopan Feb 22 '21 at 06:52
  • @vprocopan Try as one line, rather then breaking the command into multiple lines: `aws cloudformation deploy --template-file template.yml --stack-name my-stack --region eu-central-1`. – Marcin Feb 22 '21 at 09:03
  • same, unfortunately – vprocopan Feb 22 '21 at 09:07
  • @vprocopan Are you sure that the code in question is fully representative of your actual code? – Marcin Feb 22 '21 at 09:08
  • #!/bin/bash -eo pipefail aws cloudformation deploy --template-file template.yml --stack-name my-stack --region eu-central-1 Unable to locate credentials. You can configure credentials by running "aws configure". Exited with code exit status 253 CircleCI received exit code 253 – vprocopan Feb 22 '21 at 09:08
  • @vprocopan This is different issue. Region works. – Marcin Feb 22 '21 at 09:08
  • yes it is copy paste :) I would do screenshots but stack likes text better. – vprocopan Feb 22 '21 at 09:09
  • understood, where do i put the credentials? environment vars in circleci? or same in command? – vprocopan Feb 22 '21 at 09:10
  • @vprocopan `region` error is resolved now. lack of credentials is a new issue. You can pass them using envarionmental variables in circle. – Marcin Feb 22 '21 at 09:10
  • ,yes thanks! it kind of accepts the region now, but what is wrong with the credentials? as I do have them in env vars in circle, do I have to pass them directly too? – vprocopan Feb 22 '21 at 09:17
  • @vprocopan Have a look [here](https://techinscribed.com/deploy-frontend-application-to-aws-s3-using-circle-ci/) how you can safely pass your credentails to circle. – Marcin Feb 22 '21 at 09:21
  • @vprocopan It involves circle [context](https://circleci.com/docs/2.0/contexts/). – Marcin Feb 22 '21 at 09:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229033/discussion-between-vprocopan-and-marcin). – vprocopan Feb 22 '21 at 10:06
  • the `--region` flag fixed it for me thanks. – Biskrem Muhammad Sep 11 '22 at 12:47