如何使用boto3为AWS Lambda函数打标签。

3
我有一些代码,创建了一个类型为'lambda'的boto3客户端。然后我使用该客户端调用list_functions()、create_function()和update_function()方法。这在以下文档中都很好地说明了: http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.list_functions 但是当我尝试使用list_tags()或tag_resource()方法时,就会出现错误,如下所示: http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.list_tags 错误信息如下:
AttributeError: 'Lambda' object has no attribute 'list_tags'
我做错了什么?这些方法在同一文档页面上列出,因此我认为它们应该在同一客户端上调用。发生了什么问题?
    l = boto3.client(
    'lambda',
    region_name='us-east-1', 
    aws_access_key_id = 'AletitgoQ',
    aws_secret_access_key = 'XvHowdyW',
)
    l.list_tags(
         Resource="myArn"
        )        

    l.tag_resource(
            Resource="myArn",
            Tags={
                'action': 'test'
          }
      )

更糟的是,尽管文档在http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.create_function中提到了这一点,但我似乎无法在create_function()调用中包含标签。
当我在调用中包含标签时,我得到了这个响应:
botocore.exceptions.ParamValidationError:参数验证失败: 输入中的未知参数:“Tags”,必须为以下之一:FunctionName、Runtime、Role、Handler、Code、Description、Timeout、MemorySize、Publish、VpcConfig、DeadLetterConfig、Environment、KMSKeyArn。
将该列表与boto3文档中显示的内容进行比较,您会发现有一些末尾的东西缺失,包括标记。
我在使用Python 2.7,并且pip确认我的boto3版本为1.4.4
1个回答

5

对我来说,这很正常:

>>> import boto3
>>> client = boto3.client('lambda')

>>> response=client.create_function(FunctionName='bar', Runtime='python2.7', Handler='index.handler', Tags={'Action': 'Test'}, Role='arn:aws:iam::123456789012:role/my-role', Code={'S3Bucket':'my-bucket', 'S3Key':'files.zip'})

>>> client.tag_resource(Resource='arn:aws:lambda:ap-southeast-2:123456789012:function:bar', Tags={'Food':'Cheese'})
{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 204, 'RequestId': '93963c42-36d5-11e7-a457-8730520029b8', 'HTTPHeaders': {'date': 'Fri, 12 May 2017 05:40:58 GMT', 'x-amzn-requestid': '93963c42-36d5-11e7-a457-8730520029b8', 'connection': 'keep-alive', 'content-type': 'application/json'}}}

>>> client.list_tags(Resource='arn:aws:lambda:ap-southeast-2:123456789012:function:bar')
{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '9e826957-36d5-11e7-a554-a30d477976ba', 'HTTPHeaders': {'date': 'Fri, 12 May 2017 05:41:16 GMT', 'x-amzn-requestid': '9e826957-36d5-11e7-a554-a30d477976ba', 'content-length': '42', 'content-type': 'application/json', 'connection': 'keep-alive'}}, u'Tags': {u'Action': u'Test', u'Food': u'Cheese'}}

很奇怪。你能帮我一个忙,在create方法中添加一个虚假标签(如taggg),看看是否会得到与上面相同的错误信息吗? - VBAHole
我的boto3已经是最新版本了,但my botocore不是。运行pip install -U boto3解决了问题。 - VBAHole

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接