AWS Java SDK client for communicating with AWS Lambda Service for function management, invocation, and resource control
—
Comprehensive layer lifecycle operations including publishing, versioning, permission management, and deletion of Lambda layers for sharing common code and dependencies across functions.
Creates a Lambda layer from a ZIP archive containing libraries, custom runtimes, or other dependencies.
/**
* Creates a Lambda layer from ZIP archive containing dependencies or libraries
* @param request Layer publishing parameters including content, compatible runtimes, and description
* @return PublishLayerVersionResult containing layer version details and download information
* @throws ServiceException if service encounters an error
* @throws InvalidParameterValueException if parameters are invalid
* @throws ResourceConflictException if layer limit exceeded
*/
PublishLayerVersionResult publishLayerVersion(PublishLayerVersionRequest request);
public class PublishLayerVersionRequest {
/** Layer name (required) - 1-64 characters, pattern: [a-zA-Z0-9-_]+ */
private String layerName;
/** Layer description (optional) - up to 256 characters */
private String description;
/** Layer content (required) - ZIP file up to 50 MB */
private LayerVersionContentInput content;
/** Compatible runtimes (optional) - list of supported runtime environments */
private List<Runtime> compatibleRuntimes;
/** License information (optional) - up to 512 characters */
private String licenseInfo;
/** Compatible architectures (optional) - x86_64, arm64 */
private List<Architecture> compatibleArchitectures;
}
public class LayerVersionContentInput {
/** S3 bucket containing ZIP file (optional) */
private String s3Bucket;
/** S3 object key (optional) */
private String s3Key;
/** S3 object version (optional) */
private String s3ObjectVersion;
/** Base64-encoded ZIP content (optional) - max 50 MB */
private ByteBuffer zipFile;
}
public class PublishLayerVersionResult {
/** Layer version content information */
private LayerVersionContentOutput content;
/** Layer ARN */
private String layerArn;
/** Layer version ARN */
private String layerVersionArn;
/** Layer description */
private String description;
/** Creation timestamp */
private String createdDate;
/** Version number */
private Long version;
/** Compatible runtimes */
private List<Runtime> compatibleRuntimes;
/** License information */
private String licenseInfo;
/** Compatible architectures */
private List<Architecture> compatibleArchitectures;
}
public class LayerVersionContentOutput {
/** Download location (valid for 10 minutes) */
private String location;
/** SHA256 hash of layer content */
private String codeSha256;
/** Layer content size in bytes */
private Long codeSize;
/** Signing profile version ARN */
private String signingProfileVersionArn;
/** Signing job ARN */
private String signingJobArn;
}Retrieves information about a specific layer version including download location.
/**
* Retrieves layer version information with download link (valid 10 minutes)
* @param request Layer version retrieval parameters including layer name and version
* @return GetLayerVersionResult containing layer details and download information
* @throws ResourceNotFoundException if layer version does not exist
* @throws ServiceException if service encounters an error
*/
GetLayerVersionResult getLayerVersion(GetLayerVersionRequest request);
public class GetLayerVersionRequest {
/** Layer name (required) - name or ARN */
private String layerName;
/** Version number (required) */
private Long versionNumber;
}
public class GetLayerVersionResult {
/** Layer version content information */
private LayerVersionContentOutput content;
/** Layer ARN */
private String layerArn;
/** Layer version ARN */
private String layerVersionArn;
/** Layer description */
private String description;
/** Creation timestamp */
private String createdDate;
/** Version number */
private Long version;
/** Compatible runtimes */
private List<Runtime> compatibleRuntimes;
/** License information */
private String licenseInfo;
/** Compatible architectures */
private List<Architecture> compatibleArchitectures;
}Retrieves layer version information using the layer version ARN.
/**
* Retrieves layer version information by ARN
* @param request Layer version ARN retrieval parameters
* @return GetLayerVersionByArnResult containing layer details
* @throws ResourceNotFoundException if layer version does not exist
* @throws ServiceException if service encounters an error
*/
GetLayerVersionByArnResult getLayerVersionByArn(GetLayerVersionByArnRequest request);
public class GetLayerVersionByArnRequest {
/** Layer version ARN (required) */
private String arn;
}
public class GetLayerVersionByArnResult {
/** Layer version content information */
private LayerVersionContentOutput content;
/** Layer ARN */
private String layerArn;
/** Layer version ARN */
private String layerVersionArn;
/** Layer description */
private String description;
/** Creation timestamp */
private String createdDate;
/** Version number */
private Long version;
/** Compatible runtimes */
private List<Runtime> compatibleRuntimes;
/** License information */
private String licenseInfo;
/** Compatible architectures */
private List<Architecture> compatibleArchitectures;
}Deletes a specific layer version. Content remains until no functions reference it.
/**
* Deletes a layer version (content copy remains until no function references)
* @param request Layer version deletion parameters including layer name and version
* @return DeleteLayerVersionResult indicating successful deletion
* @throws ServiceException if service encounters an error
* @throws ResourceNotFoundException if layer version does not exist
*/
DeleteLayerVersionResult deleteLayerVersion(DeleteLayerVersionRequest request);
public class DeleteLayerVersionRequest {
/** Layer name (required) - name or ARN */
private String layerName;
/** Version number (required) */
private Long versionNumber;
}
public class DeleteLayerVersionResult {
// Empty result indicating successful deletion
}Lists Lambda layers with information about the latest version.
/**
* Lists Lambda layers with latest version information
* @param request Layer listing parameters including compatible runtime filter and pagination
* @return ListLayersResult containing layer list with latest versions
* @throws ServiceException if service encounters an error
*/
ListLayersResult listLayers(ListLayersRequest request);
public class ListLayersRequest {
/** Compatible runtime filter (optional) */
private Runtime compatibleRuntime;
/** Pagination marker (optional) */
private String marker;
/** Maximum items to return (optional, range: 1-50) */
private Integer maxItems;
/** Compatible architecture filter (optional) */
private Architecture compatibleArchitecture;
}
public class ListLayersResult {
/** Pagination marker for next page */
private String nextMarker;
/** List of layers with latest version info */
private List<LayersListItem> layers;
}
public class LayersListItem {
/** Layer name */
private String layerName;
/** Layer ARN */
private String layerArn;
/** Latest layer version information */
private LayerVersionsListItem latestMatchingVersion;
}
public class LayerVersionsListItem {
/** Layer version ARN */
private String layerVersionArn;
/** Version number */
private Long version;
/** Layer description */
private String description;
/** Creation timestamp */
private String createdDate;
/** Compatible runtimes */
private List<Runtime> compatibleRuntimes;
/** License information */
private String licenseInfo;
/** Compatible architectures */
private List<Architecture> compatibleArchitectures;
}Lists all versions for a specific layer.
/**
* Lists all versions for a specific layer
* @param request Layer version listing parameters including layer name and pagination
* @return ListLayerVersionsResult containing version list and pagination info
* @throws ResourceNotFoundException if layer does not exist
* @throws ServiceException if service encounters an error
*/
ListLayerVersionsResult listLayerVersions(ListLayerVersionsRequest request);
public class ListLayerVersionsRequest {
/** Layer name (required) - name or ARN */
private String layerName;
/** Compatible runtime filter (optional) */
private Runtime compatibleRuntime;
/** Pagination marker (optional) */
private String marker;
/** Maximum items to return (optional, range: 1-50) */
private Integer maxItems;
/** Compatible architecture filter (optional) */
private Architecture compatibleArchitecture;
}
public class ListLayerVersionsResult {
/** Pagination marker for next page */
private String nextMarker;
/** List of layer versions */
private List<LayerVersionsListItem> layerVersions;
}Grants permission for accounts or organizations to use a layer version.
/**
* Grants layer version usage permission to AWS accounts or organizations
* @param request Permission grant parameters including principal and action
* @return AddLayerVersionPermissionResult containing statement ID and policy
* @throws ResourceNotFoundException if layer version does not exist
* @throws ResourceConflictException if statement ID already exists
* @throws PolicyLengthExceededException if policy exceeds size limit
*/
AddLayerVersionPermissionResult addLayerVersionPermission(AddLayerVersionPermissionRequest request);
public class AddLayerVersionPermissionRequest {
/** Layer name (required) - name or ARN */
private String layerName;
/** Version number (required) */
private Long versionNumber;
/** Statement ID (required) - unique identifier for permission statement */
private String statementId;
/** Action (required) - typically "lambda:GetLayerVersion" */
private String action;
/** Principal (required) - AWS account ID, organization ID, or "*" */
private String principal;
/** Organization ID (optional) - restrict to specific organization */
private String organizationId;
/** Revision ID for optimistic locking (optional) */
private String revisionId;
}
public class AddLayerVersionPermissionResult {
/** Statement ID */
private String statementId;
/** Updated resource policy */
private String statement;
/** Revision ID */
private String revisionId;
}Revokes permission for accounts or organizations to use a layer version.
/**
* Revokes layer version usage permission
* @param request Permission revocation parameters including statement ID
* @return RemoveLayerVersionPermissionResult indicating successful removal
* @throws ResourceNotFoundException if layer version or statement does not exist
* @throws ServiceException if service encounters an error
*/
RemoveLayerVersionPermissionResult removeLayerVersionPermission(RemoveLayerVersionPermissionRequest request);
public class RemoveLayerVersionPermissionRequest {
/** Layer name (required) - name or ARN */
private String layerName;
/** Version number (required) */
private Long versionNumber;
/** Statement ID (required) - identifier of permission statement to remove */
private String statementId;
/** Revision ID for optimistic locking (optional) */
private String revisionId;
}
public class RemoveLayerVersionPermissionResult {
// Empty result indicating successful removal
}Retrieves the resource-based policy for a layer version.
/**
* Retrieves resource-based IAM policy for layer version
* @param request Policy retrieval parameters including layer name and version
* @return GetLayerVersionPolicyResult containing policy document and revision ID
* @throws ResourceNotFoundException if layer version or policy does not exist
* @throws ServiceException if service encounters an error
*/
GetLayerVersionPolicyResult getLayerVersionPolicy(GetLayerVersionPolicyRequest request);
public class GetLayerVersionPolicyRequest {
/** Layer name (required) - name or ARN */
private String layerName;
/** Version number (required) */
private Long versionNumber;
}
public class GetLayerVersionPolicyResult {
/** Resource-based policy document */
private String policy;
/** Revision ID */
private String revisionId;
}AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient();
// Upload layer from S3
LayerVersionContentInput content = new LayerVersionContentInput()
.withS3Bucket("my-bucket")
.withS3Key("layers/numpy-layer.zip");
PublishLayerVersionRequest request = new PublishLayerVersionRequest()
.withLayerName("numpy-scipy-layer")
.withDescription("NumPy and SciPy libraries for Python 3.9")
.withContent(content)
.withCompatibleRuntimes(Runtime.Python39, Runtime.Python38)
.withCompatibleArchitectures(Architecture.X86_64)
.withLicenseInfo("MIT");
PublishLayerVersionResult result = lambdaClient.publishLayerVersion(request);
System.out.println("Published layer version: " + result.getVersion());
System.out.println("Layer ARN: " + result.getLayerVersionArn());// Read ZIP file into memory
Path zipPath = Paths.get("my-layer.zip");
byte[] zipContent = Files.readAllBytes(zipPath);
LayerVersionContentInput content = new LayerVersionContentInput()
.withZipFile(ByteBuffer.wrap(zipContent));
PublishLayerVersionRequest request = new PublishLayerVersionRequest()
.withLayerName("my-utilities-layer")
.withDescription("Common utility functions")
.withContent(content)
.withCompatibleRuntimes(Runtime.Java11, Runtime.Java8al2)
.withLicenseInfo("Apache-2.0");
PublishLayerVersionResult result = lambdaClient.publishLayerVersion(request);// Grant access to specific AWS account
AddLayerVersionPermissionRequest request = new AddLayerVersionPermissionRequest()
.withLayerName("my-shared-layer")
.withVersionNumber(1L)
.withStatementId("account-123456789012")
.withAction("lambda:GetLayerVersion")
.withPrincipal("123456789012");
AddLayerVersionPermissionResult result = lambdaClient.addLayerVersionPermission(request);
// Grant public access (use with caution)
AddLayerVersionPermissionRequest publicRequest = new AddLayerVersionPermissionRequest()
.withLayerName("my-public-layer")
.withVersionNumber(1L)
.withStatementId("public-access")
.withAction("lambda:GetLayerVersion")
.withPrincipal("*");
lambdaClient.addLayerVersionPermission(publicRequest);ListLayersRequest request = new ListLayersRequest()
.withCompatibleRuntime(Runtime.Python39)
.withCompatibleArchitecture(Architecture.X86_64)
.withMaxItems(20);
ListLayersResult result = lambdaClient.listLayers(request);
for (LayersListItem layer : result.getLayers()) {
LayerVersionsListItem latest = layer.getLatestMatchingVersion();
System.out.println("Layer: " + layer.getLayerName() +
" (v" + latest.getVersion() + ")");
System.out.println("Description: " + latest.getDescription());
}GetLayerVersionRequest request = new GetLayerVersionRequest()
.withLayerName("my-layer")
.withVersionNumber(1L);
GetLayerVersionResult result = lambdaClient.getLayerVersion(request);
String downloadUrl = result.getContent().getLocation();
// URL is valid for 10 minutes - download immediately
// Use HTTP client to download from the URL
System.out.println("Download URL: " + downloadUrl);
System.out.println("SHA256: " + result.getContent().getCodeSha256());Common exceptions when working with layers:
Install with Tessl CLI
npx tessl i tessl/maven-com-amazonaws--aws-java-sdk-lambdadocs