Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services aws ec2通信和工作,aws iam命令失败_Amazon Web Services_Aws Cli - Fatal编程技术网

Amazon web services aws ec2通信和工作,aws iam命令失败

Amazon web services aws ec2通信和工作,aws iam命令失败,amazon-web-services,aws-cli,Amazon Web Services,Aws Cli,这肯定是个奇怪的问题。我有一个aws命令行用户,我在aws帐户中设置了管理员权限。当我发出aws ec2命令时,我为用户生成的凭据起作用。但当我运行aws iam命令时不会 当我运行aws iam命令时,得到的结果如下: [user@web1:~] #aws iam create-account-alias --account-alias=mcollective An error occurred (InvalidClientTokenId) when calling the CreateAc

这肯定是个奇怪的问题。我有一个aws命令行用户,我在aws帐户中设置了管理员权限。当我发出aws ec2命令时,我为用户生成的凭据起作用。但当我运行aws iam命令时不会

当我运行aws iam命令时,得到的结果如下:

[user@web1:~] #aws iam create-account-alias --account-alias=mcollective

An error occurred (InvalidClientTokenId) when calling the CreateAccountAlias operation: The security token included in the request is invalid.
但是,当我使用相同的凭据运行aws ec2子命令时,我获得了成功:

[root@web1:~] #aws ec2 describe-instances --profile=mcollective
RESERVATIONS    281933881942    r-0080cb499a0299557
INSTANCES       0       x86_64  146923690580740912      False   xen     ami-6d1c2007    i-00dcdb6cbff0d7980     t2.micro        mcollective  2016-07-27T23:56:50.000Z        ip-xxx-xx-xx-xx.ec2.internal       xx.xx.xx.xx   ec2-xx-xx-xx-xx.compute-1.amazonaws.com        xx.xxx.xx.xx    /dev/sda1       ebs     True            subnet-0e734056 hvm     vpc-909103f7
BLOCKDEVICEMAPPINGS     /dev/sda1
EBS     2016-07-23T01:26:42.000Z        False   attached        vol-0eb52f6a94c5833aa
MONITORING      disabled
NETWORKINTERFACES               0e:68:20:c5:fa:23       eni-f78223ec    281933881942    ip-xxx-xx-xx-xx.ec2.internal   xxx.xx.xx.xx   True    in-use  subnet-0e734056 vpc-909103f7
ASSOCIATION     281933881942    ec2-xxx-xx-xx-xx.compute-1.amazonaws.com        xx.xx.xx.xx
ATTACHMENT      2016-07-23T01:26:41.000Z        eni-attach-cbf11a1f     True    0       attached
GROUPS  sg-b1b3bdca     CentOS 7 -x86_64- - with Updates HVM-1602-AutogenByAWSMP-
PRIVATEIPADDRESSES      True    ip-xxx-xx-xx-xxx.ec2.internal   xxx.xx.xx.xx
ASSOCIATION     281933881942    ec2-xx-xx-xx-xx.compute-1.amazonaws.com        xx.xx.xx.xx
PLACEMENT       us-east-1a              default
PRODUCTCODES    aw0evgkw8e5c1q413zgy5pjce       marketplace
SECURITYGROUPS  sg-b1b3bdca     CentOS 7 -x86_64- - with Updates HVM-1602-AutogenByAWSMP-
STATE   16      running
TAGS    Name     mcollective
You have mail in /var/spool/mail/root
[root@web1:~] #

那么,为什么相同的凭证适用于一组aws子命令,而不适用于另一组?我真的很好奇这个

这个问题是由@garnaat回答的,但答案隐藏在问题的评论中,因此在这里引用这个答案是为了那些对此感到困惑的人:

通过使用
--profile
标志,在每个命令中使用不同的配置文件

说明:

在第一个命令中

[user@web1:~]#aws iam创建帐户别名--帐户别名=mcollective

--profile
未指定,因此会自动使用默认的aws配置文件凭据

在第二个命令中

aws ec2描述实例--profile=mcollective


--指定了配置文件
,将用户更改为root用户,然后运行此命令aws iam create account alias--account alias=MCOLECTIVE并查看其是否有效?是否确实为
用户
root
帐户配置了相同的凭据?您正在EC2上传递一个
--profile
选项命令,但你不在IAM命令上。是的!就这样。对不起,那是漫长的一天。。唉!非常感谢。