# CodeConfig

Result of binding `Code` into a `Function`.

- Source: [`aws-lambda/lib/code.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda/lib/code.ts#L247)
- Type last changed: v2.271.0 · 25 Sep 2026

## Example

TypeScript:

```ts
// 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 codeConfig: lambda.CodeConfig = {
  image: {
    imageUri: 'imageUri',

    // the properties below are optional
    cmd: ['cmd'],
    entrypoint: ['entrypoint'],
    workingDirectory: 'workingDirectory',
  },
  inlineCode: 'inlineCode',
  s3Location: {
    bucketName: 'bucketName',
    objectKey: 'objectKey',

    // the properties below are optional
    objectVersion: 'objectVersion',
  },
  s3ObjectStorageMode: lambda.S3ObjectStorageMode.COPY,
  sourceKMSKeyArn: 'sourceKMSKeyArn',
};
```

Python:

```python
from aws_cdk.aws_s3 import Location
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_lambda as lambda_

code_config = lambda.CodeConfig(
    image=lambda.CodeImageConfig(
        image_uri="imageUri",

        # the properties below are optional
        cmd=["cmd"],
        entrypoint=["entrypoint"],
        working_directory="workingDirectory"
    ),
    inline_code="inlineCode",
    s3_location=Location(
        bucket_name="bucketName",
        object_key="objectKey",

        # the properties below are optional
        object_version="objectVersion"
    ),
    s3_object_storage_mode=lambda_.S3ObjectStorageMode.COPY,
    source_kms_key_arn="sourceKMSKeyArn"
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.lambda.*;

CodeConfig codeConfig = CodeConfig.builder()
        .image(CodeImageConfig.builder()
                .imageUri("imageUri")

                // the properties below are optional
                .cmd(List.of("cmd"))
                .entrypoint(List.of("entrypoint"))
                .workingDirectory("workingDirectory")
                .build())
        .inlineCode("inlineCode")
        .s3Location(Location.builder()
                .bucketName("bucketName")
                .objectKey("objectKey")

                // the properties below are optional
                .objectVersion("objectVersion")
                .build())
        .s3ObjectStorageMode(S3ObjectStorageMode.COPY)
        .sourceKMSKeyArn("sourceKMSKeyArn")
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.Lambda;

var codeConfig = new CodeConfig {
    Image = new CodeImageConfig {
        ImageUri = "imageUri",

        // the properties below are optional
        Cmd = new [] { "cmd" },
        Entrypoint = new [] { "entrypoint" },
        WorkingDirectory = "workingDirectory"
    },
    InlineCode = "inlineCode",
    S3Location = new Location {
        BucketName = "bucketName",
        ObjectKey = "objectKey",

        // the properties below are optional
        ObjectVersion = "objectVersion"
    },
    S3ObjectStorageMode = S3ObjectStorageMode.COPY,
    SourceKMSKeyArn = "sourceKMSKeyArn"
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

codeConfig := &CodeConfig{
	Image: &CodeImageConfig{
		ImageUri: jsii.String("imageUri"),

		// the properties below are optional
		Cmd: []*string{
			jsii.String("cmd"),
		},
		Entrypoint: []*string{
			jsii.String("entrypoint"),
		},
		WorkingDirectory: jsii.String("workingDirectory"),
	},
	InlineCode: jsii.String("inlineCode"),
	S3Location: &Location{
		BucketName: jsii.String("bucketName"),
		ObjectKey: jsii.String("objectKey"),

		// the properties below are optional
		ObjectVersion: jsii.String("objectVersion"),
	},
	S3ObjectStorageMode: awscdk.Aws_lambda.S3ObjectStorageMode_COPY,
	SourceKMSKeyArn: jsii.String("sourceKMSKeyArn"),
}
```

## Properties

- `image`: [CodeImageConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.CodeImageConfig.html) — Docker image configuration (mutually exclusive with `s3Location` and `inlineCode`).

  **Default:** code is not an ECR container image

- `inlineCode`: string — Inline code (mutually exclusive with `s3Location` and `image`).

  **Default:** code is not inline code

- `s3Location`: [Location](/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Location.html) — The location of the code in S3 (mutually exclusive with `inlineCode` and `image`).

  **Default:** code is not an s3 location

- `s3ObjectStorageMode`: [S3ObjectStorageMode](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.S3ObjectStorageMode.html) — How Lambda manages the storage of your code package.

  **Default:** Lambda copies the deployment package from your S3 bucket into Lambda-managed storage.

- `sourceKMSKeyArn`: string — The ARN of the KMS key that Lambda uses to encrypt the deployment package in Lambda-managed storage.

  **Default:** Lambda uses an AWS owned key

  This is not the key used to encrypt the source object in Amazon S3.
