如何使用 boto3 标记 AWS Lambda 函数

VBA*_*ole 3 boto3 aws-lambda

我有创建“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”对象没有属性“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'
          }
      )
Run Code Online (Sandbox Code Playgroud)

更糟糕的是,尽管文档在这里这么说,但我似乎无法在 create_function() 调用中包含标签: http://boto3.readthedocs.io/en/latest/reference/services/ lambda.html#Lambda.Client.create_function

当我在通话中包含标签时,我得到以下响应:

botocore.exceptions.ParamValidationError:参数验证失败:输入中的未知参数:“标签”,必须是以下之一:FunctionName、Runtime、Role、Handler、Code、Description、Timeout、MemorySize、Publish、VpcConfig、DeadLetterConfig、Environment、KMSKeyArn

将该列表与 boto3 文档中显示的内容进行比较,您会发现最后缺少一些内容,包括标签

我使用的是 python 2.7,pip 确认我的 boto3 是 1.4.4

Joh*_*ein 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'}}
Run Code Online (Sandbox Code Playgroud)