CodeProperty Struct
The deployment package for a Lambda function. To deploy a function defined as a container image, you specify the location of a container image in the Amazon ECR registry. For a .zip file deployment package, you can specify the location of an object in Amazon S3. For Node.js and Python functions, you can specify the function code inline in the template.
When you specify source code inline for a Node.js function, the
indexfile that CloudFormation creates uses the extension.js. This means that Node.js treats the file as a CommonJS module.
Changes to a deployment package in Amazon S3 or a container image in ECR are not detected automatically during stack updates. To update the function code, change the object key or version in the template.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_lambda as lambda } from 'aws-cdk-lib';
const codeProperty: lambda.CfnFunction.CodeProperty = {
imageUri: 'imageUri',
s3Bucket: 's3Bucket',
s3Key: 's3Key',
s3ObjectStorageMode: 's3ObjectStorageMode',
s3ObjectVersion: 's3ObjectVersion',
sourceKmsKeyArn: 'sourceKmsKeyArn',
zipFile: 'zipFile',
};
Properties
The bucket can be in a different AWS account .
s3ObjectStorageModestrings3_object_storage_modestrs3ObjectStorageModeStringS3ObjectStorageModestringS3ObjectStorageMode*string#Use COPY to store the package in LAMlong-managed storage. Use REFERENCE to read the package directly from the Amazon S3 bucket. If omitted, the default is COPY.
s3ObjectVersionstrings3_object_versionstrs3ObjectVersionStringS3ObjectVersionstringS3ObjectVersion*string#sourceKmsKeyArnstringsource_kms_key_arnstrsourceKmsKeyArnStringSourceKmsKeyArnstringSourceKmsKeyArn*string#notes
When you specify source code inline for a Node.js function, the
indexfile that CloudFormation creates uses the extension.js. This means that Node.js treats the file as a CommonJS module.When using Node.js 24 or later, Node.js can automatically detect if a
.jsfile should be treated as CommonJS or as an ES module. To enable auto-detection, add the--experimental-detect-moduleflag to theNODE_OPTIONSenvironment variable. For more information, see Experimental Node.js features .
For JSON, you must escape quotes and special characters such as newline ( \n ) with a backslash.
If you specify a function that interacts with an AWS CloudFormation custom resource, you don't have to write your own functions to send responses to the custom resource that invoked the function. AWS CloudFormation provides a response module ( cfn-response ) that simplifies sending responses. See Using AWS Lambda with AWS CloudFormation for details.