AWS Java SDK client for communicating with AWS Lambda Service for function management, invocation, and resource control
—
Resource tagging enables metadata management for Lambda functions and resources, supporting organization, cost allocation, access control, and automation workflows.
Adds metadata tags to a Lambda function for organization, cost tracking, and access control.
/**
* Adds tags to a function
* @param tagResourceRequest - Request specifying resource ARN and tags to add
* @return TagResourceResult confirming successful tagging
*/
TagResourceResult tagResource(TagResourceRequest tagResourceRequest);Usage Example:
import com.amazonaws.services.lambda.*;
import com.amazonaws.services.lambda.model.*;
import java.util.HashMap;
import java.util.Map;
AWSLambda lambdaClient = AWSLambdaClientBuilder.standard()
.withRegion("us-east-1")
.build();
// Add tags to a function
Map<String, String> tags = new HashMap<>();
tags.put("Environment", "production");
tags.put("Team", "backend");
tags.put("Project", "user-service");
tags.put("CostCenter", "engineering");
TagResourceRequest tagRequest = new TagResourceRequest()
.withResource("arn:aws:lambda:us-east-1:123456789012:function:my-function")
.withTags(tags);
TagResourceResult result = lambdaClient.tagResource(tagRequest);
System.out.println("Tags added successfully");Removes specified tags from a Lambda function.
/**
* Removes tags from a function
* @param untagResourceRequest - Request specifying resource ARN and tag keys to remove
* @return UntagResourceResult confirming successful tag removal
*/
UntagResourceResult untagResource(UntagResourceRequest untagResourceRequest);Usage Example:
import java.util.Arrays;
// Remove specific tags from a function
UntagResourceRequest untagRequest = new UntagResourceRequest()
.withResource("arn:aws:lambda:us-east-1:123456789012:function:my-function")
.withTagKeys(Arrays.asList("Environment", "OldTag"));
UntagResourceResult untagResult = lambdaClient.untagResource(untagRequest);
System.out.println("Tags removed successfully");Retrieves all tags associated with a Lambda function.
/**
* Returns a function's tags
* @param listTagsRequest - Request specifying the resource ARN
* @return ListTagsResult containing all tags for the resource
*/
ListTagsResult listTags(ListTagsRequest listTagsRequest);Usage Example:
// List all tags for a function
ListTagsRequest listRequest = new ListTagsRequest()
.withResource("arn:aws:lambda:us-east-1:123456789012:function:my-function");
ListTagsResult listResult = lambdaClient.listTags(listRequest);
Map<String, String> functionTags = listResult.getTags();
System.out.println("Function tags:");
for (Map.Entry<String, String> tag : functionTags.entrySet()) {
System.out.println(" " + tag.getKey() + ": " + tag.getValue());
}// Tag resource request
public class TagResourceRequest {
private String resource;
private java.util.Map<String, String> tags;
// ... getters and setters
}
// Untag resource request
public class UntagResourceRequest {
private String resource;
private java.util.List<String> tagKeys;
// ... getters and setters
}
// List tags request
public class ListTagsRequest {
private String resource;
// ... getters and setters
}
// List tags result
public class ListTagsResult {
private java.util.Map<String, String> tags;
// ... getters and setters
}Consistent Naming: Use consistent tag key naming conventions across your organization.
Required Tags: Implement required tags for cost center, environment, and owner identification.
Automation: Use tags to drive automation workflows and resource lifecycle management.
Cost Allocation: Leverage tags for detailed cost tracking and chargeback processes.
Access Control: Use tag-based IAM policies to control resource access.
Install with Tessl CLI
npx tessl i tessl/maven-com-amazonaws--aws-java-sdk-lambdadocs