我创建了一个名为“AMIRole”的新 IAM 角色,并为其附加了“AmazonS3FullAccess”策略。现在我用这个 IAM 角色启动一个 EC2 实例。
当我通过 SSH 连接到实例时,我可以像这样访问 AWS 访问密钥和秘密密钥:
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/AMIRole
{
"Code" : "Success",
"LastUpdated" : "2016-12-21T16:05:26Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "ABCDEFJK",
"SecretAccessKey" : "SECRET",
"Token" : "TOKEN",
"Expiration" : "2016-12-21T22:38:16Z"
}
但是,当我尝试使用此角色创建存储桶时,我收到此 AWS KEY 不存在的错误消息。
>>> import boto3
>>> s3 = boto3.resource("s3", aws_access_key_id="ABCDEFJK", aws_secret_access_key="SECRET")
>>> s3.create_bucket(Bucket="something-specific-uuid")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/boto3/resources/factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 159, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 494, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidAccessKeyId) when calling the CreateBucket operation: The AWS Access Key Id you provided does not exist in our records.
我的目标是创建一个具有轮换访问/密钥的 AMI,以便我可以将 AMI 放在 AWS Marketplace 上。