Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.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
Python 获取ElastiCache标签_Python_Amazon Web Services_Boto_Amazon Elasticache_Boto3 - Fatal编程技术网

Python 获取ElastiCache标签

Python 获取ElastiCache标签,python,amazon-web-services,boto,amazon-elasticache,boto3,Python,Amazon Web Services,Boto,Amazon Elasticache,Boto3,我正在尝试使用Boto3和Python获取ElastiCache标记。在boto3中,有一个名为-list\u tags\u的函数,用于\u resource()。但是,我面临的问题是,如何找到资源名称。我正在使用以下代码: from boto3.session import Session sess = Session(aws_access_key_id=id,aws_secret_access_key=key) conn = sess.client(service_name='elasti

我正在尝试使用Boto3和Python获取ElastiCache标记。在boto3中,有一个名为-list\u tags\u的函数,用于\u resource()。但是,我面临的问题是,如何找到资源名称。我正在使用以下代码:

from boto3.session import Session

sess = Session(aws_access_key_id=id,aws_secret_access_key=key)
conn = sess.client(service_name='elasticache', region_name='us-east-1')
arn="arn:aws:elasticache:us-east-1:123456:cluster:name_of_cluster"
print conn.list_tags_for_resource(ResourceName=name)
这将导致以下错误:

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the ListTagsForResource operation: Unauthorized call. Please check the region or customer id

如果您使用的是ReadOnlyAccess管理策略,您将无法列出elasticache的标记。确保用户的策略中明确设置了elasticache:ListTagsForResource。亚马逊目前在其ReadOnlyAccess策略中未包含该权限。允许查看elasticache标记的策略如下所示:

{
    "Version": "2015-06-26",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticache:ListTagsForResource"
            ],
            "Resource": "*"
        }
    ]
}
我认为这应该是ReadOnlyAccess政策的一部分,并在亚马逊开了一张罚单。他们的回答是:

您提出了一个关于“elasticache:ListTagsForResource”未包含在AWS提供的“ReadOnlyAccess”托管策略中的有效观点。在我看来,当它不允许有人在命名资源上列出标记时,我们不能很好地称之为只读。因此,我与控制这些管理策略的团队建立了内部关系;请求将API“elasticache:ListTagsForResource”添加到“ReadOnlyAccess”


发布的脚本有一些问题。 您正在传递未定义的变量“name”。 我想你指的是arn,也许还有其他方法,但我在会话中定义区域名称,而不是客户端名称。 试试这样的

session = boto3.Session(region_name='us-east-1',aws_access_key_id=id,aws_secret_access_key=key)
client = session.client("elasticache")
arn = "arn:aws:elasticache:us-east-1:1234567889:cluster:rand57hzn577a78-0001-001"
client.list_tags_for_resource(ResourceName=arn)

您收到的错误表明您提供的凭据不正确。仔细检查您的访问密钥和密钥。凭据正常。基本上,问题是如何获得ResourceName?我不确定这是真的。我尝试了一个带有无效ARN的测试用例,得到的是CacheClusterNotFound错误,而不是您得到的错误。但是,如果您在构建ARN时没有有效的帐户id(示例中显示为123456),则可能会出现此错误。您是否使用了正确的帐户ID?是的,我认为没有办法通过AWS API获取缓存集群的ARN。你只需要猜测它(就像你在例子中做的那样)。如果您的信用良好,您可能没有在ARN中替换正确的帐号。再次检查ARN的
123456
部分是否有正确的帐号。