错误运行命令aws ecs list-container-instances时必须指定一个区域

use*_*375 61 amazon-ec2 amazon-web-services aws-cli

我正在尝试使用aws容器服务,根据http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_GetStarted.html中的文档

运行命令时抛出以下错误:

aws ecs list-container-instances --cluster default

You must specify a region. You can also configure your region by running "aws configure".
Run Code Online (Sandbox Code Playgroud)

该文档未提及有关指定默认区域的任何信息.我们如何在控制台中执行此操作?

Pey*_*rov 59

我想你需要使用例如:

aws ecs list-container-instances --cluster default --region us-east-1
Run Code Online (Sandbox Code Playgroud)

这当然取决于您所在的地区.


Jas*_*son 36

"您必须指定区域"不是ECS特定错误,任何AWS API/CLI/SDK命令都可能发生这种错误.

对于CLI,请设置AWS_DEFAULT_REGION环境变量.例如

export AWS_DEFAULT_REGION=us-east-1

或者在CLI配置文件中设置它:〜/ .aws/config

[default]
region=us-east-1
Run Code Online (Sandbox Code Playgroud)

或使用CLI调用传递/覆盖它:

aws ecs list-container-instances --cluster default --region us-east-1

  • 有关所有可用变量,请参阅:[AWS CLI 配置变量](https://docs.aws.amazon.com/cli/latest/topic/config-vars.html) (2认同)

Ina*_*mus 15

#1-运行此命令以一劳永逸地配置区域:

aws configure set region us-east-1 --profile admin
Run Code Online (Sandbox Code Playgroud)
  • admin如果配置文件不同,请在配置文件旁边进行更改

  • us-east-1如果您的地区不同,请更改.

#2-再次运行命令:

aws ecs list-container-instances --cluster default
Run Code Online (Sandbox Code Playgroud)

  • 这不是运行`aws configure`或编辑`.aws/config`,这是唯一对我有用的东西 (3认同)

Put*_*nik 13

如果您已配置了所需的所有内容.aws/config,但.aws/credentials仍然出现此错误 - 请仔细检查方括号中的名称。

它应该[profile myLovelyAccName]config[myLovelyAccName]credentials

需要注意的两点:

  • “profile”一词及其后一个空格 -config仅在文件中
  • acc 名称中没有拼写错误!

  • `~/.aws/config` 中缺少“profile”前缀是我的原因。谢谢你! (4认同)

Rad*_*ive 6

只是为了添加 Dimitrov 先生和 Jason 的回答,如果您使用的是特定配置文件并且您已经将您的区域设置放在那里,那么对于您需要添加的所有请求

“--profile”选项。

例如:

假设您有 AWS Playground 配置文件,并且 ~/.aws/config 有 [profile playground] 进一步具有类似的内容,

[profile playground] region=us-east-1

然后,使用类似下面的东西

aws ecs list-container-instances --cluster default --profile playground


use*_*375 3

我发布得太早了,但是下面的链接给出了配置方法

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

下面的链接给出了获取访问密钥的方法

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#cli-signup