Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tag an AWS Lambda function using boto3

I have code that creates a boto3 client of type 'lambda'. I then use that client to call the list_functions(), create_function(), and update_function() methods. That all works well as outlined in this documentation: http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.list_functions

But when i go to use the list_tags() or tag_resource() methods outline here: http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.list_tags

I get an error saying:

AttributeError: 'Lambda' object has no attribute 'list_tags'

what am I doing wrong? Those methods are listed on the same doc page so I figure they are called on the same client. What gives:

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

To make matters worse, I don't appear to be able to include the tags in the create_function() call despite what the docs say about that here: http://boto3.readthedocs.io/en/latest/reference/services/lambda.html#Lambda.Client.create_function

when i include tags in the call i get this response:

botocore.exceptions.ParamValidationError: Parameter validation failed: Unknown parameter in input: "Tags", must be one of: FunctionName, Runtime, Role, Handler, Code, Description, Timeout, MemorySize, Publish, VpcConfig, DeadLetterConfig, Environment, KMSKeyArn

compare that list to what is shown in the boto3 docs and you see that a few things are missing at the end there including tags

I'm in python 2.7 and pip confirms my boto3 is 1.4.4

like image 750
VBAHole Avatar asked Jun 24 '26 15:06

VBAHole


1 Answers

It works just fine for me:

>>> 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'}}
like image 109
John Rotenstein Avatar answered Jun 27 '26 21:06

John Rotenstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!