0

I would like to run an EC2 in another region without having to change aws configuration. This is a script that should run for other users as well. I know that it is possible to create an SG in another region just by passing the argument --region us-east-2 .. but doesn't work for Runinstances api.

Another solution would be a script that runs aws configure and change ONLY the region, without any input from the user. any idea on how to implement any of these 2 ?

Aziz bel
  • 21
  • 2

1 Answers1

1

--region works for all aws cli commands. It is a top-level parameter documented here. If that isn't working for you, you should show the details of that in your question.

Also, aws configure only sets the default region. You can override the current region at any time by setting the AWS_REGION environment variable. You could do this inside your script before calling aws cli commands.

See the aws cli environment variable documentation.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • Thank you Mark, i'm currently configured as `us-east-1` and when i run `aws ec2 run-instances --region us-east-2 --image-id ami-04899638f181c1fb0 --keyname ec2keypair` i get an error: `An error occurred (Unsupported) when calling the RunInstances operation: The requested configuration is currently not supported. Please check the documentation for supported configurations.` – Aziz bel Jul 26 '22 at 15:48
  • 1
    Are you sure the AMI with that ID, and the keypair with that name, exist in `us-east-2`? – Mark B Jul 26 '22 at 16:04
  • The ami you've selected might not be compatible with the default `m1.small` instance type. – Anon Coward Jul 26 '22 at 19:38