首页 文章

如何使用boto3标记AWS Lambda函数

提问于
浏览
2

我有代码创建类型为'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'

我究竟做错了什么?这些方法列在同一个doc页面上,所以我认为它们是在同一个客户端上调用的 . 是什么赋予了:

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'
          }
      )

更糟糕的是,我似乎无法在create_function()调用中包含标记,尽管文档在此处对此进行了说明:http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.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 回答

  • 4

    它适用于我:

    >>> 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'}}
    

相关问题