Menu
AWS Lambda
Developer Guide

Tagging Lambda Functions

Lambda functions can span multiple applications across separate regions. To simplify the process of tracking the frequency and cost of each function invocation, you can use tags. Tags are key-value pairs that you attach to AWS resources to better organize them. They are particularly useful when you have many resources of the same type, which in the case of AWS Lambda, is a function. By using tags, customers with hundreds of Lambda functions can easily access and analyze a specific set by filtering on those that contain the same tag. Two of the key advantages of tagging your Lambda functions are:

  • Grouping and Filtering: By applying tags, you can use the Lambda console or CLI to isolate a list of Lambda functions contained within a specific application or billing department. For more information, see Filtering on Tagged Lambda Functions.

  • Cost allocation: Because Lambda's support for tagging is integrated with AWS Billing, you can break down bills into dynamic categories and map functions to specific cost centers. For example, if you tag all Lambda functions with a "Department" key, then all AWS Lambda costs can be broken down by department. You can then provide an individual department value, such "Department 1" or "Department 2" to direct the function invocation cost to the appropriate cost center. Cost allocation is surfaced via detailed billing reports, making it easier for you to categorize and track your AWS costs.

Tagging Lambda Functions for Billing

You can use tags to organize your AWS bill to reflect your own cost structure. To do this, you can add tag keys whose values will be included in the cost allocation report. For more information about setting up a cost allocation report that includes the tag keys you select to be included as line items in the report, see The Monthly Cost Allocation Report in About AWS Account Billing.

To see the cost of your combined resources, you can organize your billing information based on functions that have the same tag key values. For example, you can tag several Lambda functions with a specific application name, and then organize your billing information to see the total cost of that application across several services. For more information, see Using Cost Allocation Tags in the AWS Billing and Cost Management User Guide.

Important

In AWS Lambda the only resource that can be tagged is a function. You cannot tag an alias or a specific function version. Any invocation of a function's alias or version will be billed as an invocation of the original function.

Applying Tags to Lambda Functions

How you tag your Lambda functions depends on how you create the function. You can apply them using the Lambda console or CLI, as explained in the following sections:

Applying Tags to Lambda Functions Using the Console

You can add tags to your function under the Tags section in the configuration tab.

To remove tags from an existing function, open the function, choose the Tags section and then choose the Remove button next to key-value pair.

Applying Tags to Lambda Functions Using the CLI

When you create a new Lambda function using the CreateFunction command, you can add tags by populating the Tags parameter. Specify multiple tag values by enclosing them in quotation marks, as shown below:

Copy
$ aws lambda create-function \ --region region \ --function-name function-name --role role-arn \ --handler handler-name \ --runtime runtime-value \ --runtime runtime \ --tags "DEPARTMENT=Department A, Department B" \ --profile adminuser \ --timeout 10 \ --memory-size 1024

To apply or add more tags to an existing function, you can use the TagResource API and supply it with the Lambda function ARN (Amazon Resource Name) along with the key-value pairs that comprise your tags.

Copy
$ aws lambda tag-resource \ --resource function arn \ --tags DEPARTMENT="Department C, Department D"

Conversely, if you want to remove any or all tags from a Lambda function, you use the UntagResource API and again supply the function ARN (Amazon Resource Name), along with a list of tag keys to be removed from the function.

Copy
$ aws lambda untag-resource \ --resource function arn \ --tagkeys list of tag keys to be removed

Filtering on Tagged Lambda Functions

Once you have grouped your Lambda functions by using tags, you can leverage the filtering capabilities provided by the Lambda console or the AWS CLI to view them based on your specific requirements.

Filtering Lambda Functions Using the Console

The Lambda console contains a search field that allows you to filter the list of functions based on a specified set of function attributes, including Tags. Suppose you have two functions named MyFunction and MyFunction2 that have a Tags key called Department. To view those functions, choose the search field and notice the automatic filtering that includes a list of the Tags keys:

Choose the Department key. Lambda will return any function that contains that key.

Now suppose that the key value of the MyFunction tag is "Department A" and the key value of MyFunction2 is "Department B". You can narrow your search by choosing the value of the Department key, in this case Department A, as shown below.

This will return only MyFunction.

You can further narrow your search by including the other accepted Function attributes, including Description, Function name or Runtime.

Note

You are limited to a maximum of 50 tags per Lambda function. If you delete the Lambda function, the associated tags will also be deleted.

Filtering Lambda Functions Using the CLI

If you want to view the tags that are applied to a specific Lambda function, you can use either of the following Lambda API commands:

  • ListTags: You supply your Lambda function ARN (Amazon Resource Name) to view a list of the tags associated with this function:

    Copy
    $ aws lambda list-tags \ --resource function arn \ --region region \ --profile adminuser
  • GetFunction: You supply your Lambda function name to a view a list of the tags associated with this function:

    Copy
    $ aws lambda get-function \ --function-name function name \ --region region \ --profile adminuser

You can also use the AWS Tagging Service’s GetResources API to filter your resources by tags. The GetResources API receives up to 10 filters, with each filter containing a tag key and up to 10 tag values. You provide GetResources with a ‘ResourceType’ to filter by specific resource types. For more information about the AWS Tagging Service, see Working with Resource Groups.

Tag Restrictions

The following restrictions apply to tags:

  • Maximum number of tags per resource—50

  • Maximum key length—127 Unicode characters in UTF-8

  • Maximum value length—255 Unicode characters in UTF-8

  • Tag keys and values are case sensitive.

  • Do not use the aws: prefix in your tag names or values because it is reserved for AWS use. You can't edit or delete tag names or values with this prefix. Tags with this prefix do not count against your tags per resource limit.

  • If your tagging schema will be used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, spaces, and numbers representable in UTF-8, plus the following special characters: + - = . _ : / @.