> **Experimental**
>
> `@aws-cdk/aws-lambda-python-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# PythonFunctionProps

Properties for a PythonFunction.

Extends: PythonFunctionProps
Extends: FunctionOptions
Used as props by: PythonFunction

- Stability: [Experimental](/cdk/api/stability.html)
- Source: [`lib/function.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0-alpha.0/packages/@aws-cdk/aws-lambda-python-alpha/lib/function.ts#L15)

## Example

```ts
const entry = '/path/to/function';
const image = DockerImage.fromBuild(entry);

new python.PythonFunction(this, 'function', {
  entry,
  runtime: Runtime.PYTHON_3_8,
  bundling: {
    buildArgs: { PIP_INDEX_URL: "https://your.index.url/simple/", PIP_EXTRA_INDEX_URL: "https://your.extra-index.url/simple/" },
  },
});
```

## Properties

- `adotInstrumentation`: [AdotInstrumentationConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.AdotInstrumentationConfig.html) — Specify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation.

  **Default:** No ADOT instrumentation

- `allowAllIpv6Outbound`: boolean = false — Whether to allow the Lambda to send all ipv6 network traffic.

  If set to true, there will only be a single egress rule which allows all
  outbound ipv6 traffic. If set to false, you must individually add traffic rules to allow the
  Lambda to connect to network targets using ipv6.

  Do not specify this property if the `securityGroups` or `securityGroup` property is set.
  Instead, configure `allowAllIpv6Outbound` directly on the security group.

- `allowAllOutbound`: boolean = true — Whether to allow the Lambda to send all network traffic (except ipv6).

  If set to false, you must individually add traffic rules to allow the
  Lambda to connect to network targets.

  Do not specify this property if the `securityGroups` or `securityGroup` property is set.
  Instead, configure `allowAllOutbound` directly on the security group.

- `allowPublicSubnet`: boolean = false — Lambda Functions in a public subnet can NOT access the internet.

  Use this property to acknowledge this limitation and still place the function in a public subnet.

- `applicationLogLevel`: string = "INFO" — Use `applicationLogLevelV2` as a property instead.

- `applicationLogLevelV2`: [ApplicationLogLevel](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ApplicationLogLevel.html) = ApplicationLogLevel.INFO — Sets the application log level for the function.

- `architecture`: [Architecture](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Architecture.html) = Architecture.X86_64 — The system architectures compatible with this lambda function.

- `bundling`: [BundlingOptions](/cdk/api/v2/docs/@aws-cdk_aws-lambda-python-alpha.BundlingOptions.html) — Bundling options to use for this function.

  **Default:** Use the default bundling Docker image, with x86_64 architecture.

  Use this to specify custom bundling options like
  the bundling Docker image, asset hash type, custom hash, architecture, etc.

- `codeSigningConfig`: [ICodeSigningConfigRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_lambda.ICodeSigningConfigRef.html) — Code signing config associated with this function.

  **Default:** Not Sign the Code

- `currentVersionOptions`: [VersionOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.VersionOptions.html) — Options for the `lambda.Version` resource automatically created by the `fn.currentVersion` method.

  **Default:** default options as described in `VersionOptions`

- `deadLetterQueue`: [IQueue](/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.IQueue.html) — The SQS queue to use if DLQ is enabled.

  **Default:** SQS queue with 14 day retention period if `deadLetterQueueEnabled` is `true`

  If SNS topic is desired, specify `deadLetterTopic` property instead.

- `deadLetterQueueEnabled`: boolean — Enabled DLQ.

  **Default:** false unless `deadLetterQueue` is set, which implies DLQ is enabled.

  If `deadLetterQueue` is undefined,
  an SQS queue with default options will be defined for your Function.

- `deadLetterTopic`: [ITopic](/cdk/api/v2/docs/aws-cdk-lib.aws_sns.ITopic.html) — The SNS topic to use as a DLQ.

  **Default:** no SNS topic

  Note that if `deadLetterQueueEnabled` is set to `true`, an SQS queue will be created
  rather than an SNS topic. Using an SNS topic as a DLQ requires this property to be set explicitly.

- `description`: string — A description of the function.

  **Default:** No description.

- `durableConfig`: [DurableConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.DurableConfig.html) — The durable configuration for the function.

  **Default:** No durable configuration

  If durability is added to an existing function, a resource replacement will be triggered.
  See the 'durableConfig' section in the module README for more details.

- `entry`: string (required) — Path to the source of the function or the location for dependencies.

- `environment`: { [key: string]: string } — Key-value pairs that Lambda caches and makes available for your Lambda functions.

  **Default:** No environment variables.

  Use environment variables to apply configuration changes, such
  as test and production environment configurations, without changing your
  Lambda function source code.

- `environmentEncryption`: [IKeyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_kms.IKeyRef.html) — The AWS KMS key that's used to encrypt your function's environment variables.

  **Default:** AWS Lambda creates and uses an AWS managed customer master key (CMK).

- `ephemeralStorageSize`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) — The size of the function’s /tmp directory in MiB.

  **Default:** 512 MiB

- `events`: [IEventSource](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IEventSource.html)[] — Event sources for this function.

  **Default:** No event sources.

  You can also add event sources using `addEventSource`.

- `filesystem`: [FileSystem](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.FileSystem.html) — The filesystem configuration for the lambda function.

  **Default:** will not mount any filesystem

- `functionName`: string — A name for the function.

  **Default:** AWS CloudFormation generates a unique physical ID and uses that ID for the function's name. For more information, see Name Type.

- `handler`: string = handler — The name of the exported handler in the index file.

- `index`: string = index.py — The path (relative to entry) to the index file containing the exported handler.

- `initialPolicy`: [PolicyStatement](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyStatement.html)[] — Initial policy statements to add to the created Lambda Role.

  **Default:** No policy statements are added to the created Lambda role.

  You can call `addToRolePolicy` to the created lambda to add statements post creation.

- `insightsVersion`: [LambdaInsightsVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LambdaInsightsVersion.html) — Specify the version of CloudWatch Lambda insights to use for monitoring.

  **Default:** No Lambda Insights

- `ipv6AllowedForDualStack`: boolean = false — Allows outbound IPv6 traffic on VPC functions that are connected to dual-stack subnets.

  Only used if 'vpc' is supplied.

- `layers`: [ILayerVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ILayerVersion.html)[] — A list of layers to add to the function's execution environment.

  **Default:** No layers.

  You can configure your Lambda function to pull in
  additional code during initialization in the form of layers. Layers are packages of libraries or other dependencies
  that can be used by multiple functions.

- `logFormat`: string = "Text" — Use `loggingFormat` as a property instead.

- `loggingFormat`: [LoggingFormat](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LoggingFormat.html) = LoggingFormat.TEXT — Sets the loggingFormat for the function.

- `logGroup`: [ILogGroupRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_logs.ILogGroupRef.html) — The log group the function sends logs to.

  **Default:** `/aws/lambda/${this.functionName}` - default log group created by Lambda

  By default, Lambda functions send logs to an automatically created default log group named /aws/lambda/\<function name\>.
  However you cannot change the properties of this auto-created log group using the AWS CDK, e.g. you cannot set a different log retention.

  Use the `logGroup` property to create a fully customizable LogGroup ahead of time, and instruct the Lambda function to send logs to it.

  Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
  If you are deploying to another type of region, please check regional availability first.

- `logRemovalPolicy`: [RemovalPolicy](/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) = RemovalPolicy.Retain — use `logGroup` instead

  Normally you want to retain the log group so you can diagnose issues
  from logs even after a deployment that no longer includes the log group.
  In that case, use the normal date-based retention policy to age out your
  logs.

- `logRetention`: [RetentionDays](/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html) = logs.RetentionDays.INFINITE — use `logGroup` instead

  When updating
  this property, unsetting it doesn't remove the log retention policy. To
  remove the retention policy, set the value to `INFINITE`.

  This is a legacy API and we strongly recommend you move away from it if you can.
  Instead create a fully customizable log group with `logs.LogGroup` and use the `logGroup` property
  to instruct the Lambda function to send logs to it.
  Migrating from `logRetention` to `logGroup` will cause the name of the log group to change.
  Users and code and referencing the name verbatim will have to adjust.

  In AWS CDK code, you can access the log group name directly from the LogGroup construct:
  ```ts
  import * as logs from 'aws-cdk-lib/aws-logs';

  declare const myLogGroup: logs.LogGroup;
  myLogGroup.logGroupName;
  ```

- `logRetentionRetryOptions`: [LogRetentionRetryOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LogRetentionRetryOptions.html) — When log retention is specified, a custom resource attempts to create the CloudWatch log group.

  **Default:** Default AWS SDK retry options.

  These options control the retry policy when interacting with CloudWatch APIs.

  This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
  `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.

- `logRetentionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role for the Lambda function associated with the custom resource that sets the retention policy.

  **Default:** A new role is created.

  This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
  `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.

- `maxEventAge`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.hours(6) — The maximum age of a request that Lambda sends to a function for processing.

  Minimum: 60 seconds
  Maximum: 6 hours

- `memorySize`: number = 128 — The amount of memory, in MB, that is allocated to your Lambda function.

  Lambda uses this value to proportionally allocate the amount of CPU
  power. For more information, see Resource Model in the AWS Lambda
  Developer Guide.

- `onFailure`: [IDestination](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IDestination.html) — The destination for failed invocations.

  **Default:** no destination

- `onSuccess`: [IDestination](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IDestination.html) — The destination for successful invocations.

  **Default:** no destination

- `paramsAndSecrets`: [ParamsAndSecretsLayerVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ParamsAndSecretsLayerVersion.html) — Specify the configuration of Parameters and Secrets Extension.

  **Default:** No Parameters and Secrets Extension

- `profiling`: boolean — Enable profiling.

  **Default:** No profiling.

- `profilingGroup`: [IProfilingGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_codeguruprofiler.IProfilingGroup.html) — Profiling Group.

  **Default:** A new profiling group will be created if `profiling` is set.

- `recursiveLoop`: [RecursiveLoop](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.RecursiveLoop.html) = RecursiveLoop.Terminate — Sets the Recursive Loop Protection for Lambda Function.

  It lets Lambda detect and terminate unintended recursive loops.

- `reservedConcurrentExecutions`: number — The maximum of concurrent executions you want to reserve for the function.

  **Default:** No specific limit - account limit.

- `retryAttempts`: number = 2 — The maximum number of times to retry when the function returns an error.

  Minimum: 0
  Maximum: 2

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — Lambda execution role.

  **Default:** A unique role will be generated for this lambda function. Both supplied and generated roles can always be changed by calling `addToRolePolicy`.

  This is the role that will be assumed by the function upon execution.
  It controls the permissions that the function will have. The Role must
  be assumable by the 'lambda.amazonaws.com' service principal.

  The default Role automatically has permissions granted for Lambda execution. If you
  provide a Role, you must add the relevant AWS managed policies yourself.

  The relevant managed policies are "service-role/AWSLambdaBasicExecutionRole" and
  "service-role/AWSLambdaVPCAccessExecutionRole".

- `runtime`: [Runtime](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Runtime.html) (required) — The runtime environment.

  Only runtimes of the Python family are
  supported.

- `runtimeManagementMode`: [RuntimeManagementMode](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.RuntimeManagementMode.html) = Auto — Sets the runtime management configuration for a function's version.

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The list of security groups to associate with the Lambda's network interfaces.

  **Default:** If the function is placed within a VPC and a security group is not specified, either by this or securityGroup prop, a dedicated security group will be created for this function.

  Only used if 'vpc' is supplied.

- `snapStart`: [SnapStartConf](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.SnapStartConf.html) — Enable SnapStart for Lambda Function.

  **Default:** No snapstart

  SnapStart is currently supported for Java 11, Java 17, Python 3.12, Python 3.13, and .NET 8 runtime,
  as well as container image (OCI) deployments.

- `systemLogLevel`: string = "INFO" — Use `systemLogLevelV2` as a property instead.

- `systemLogLevelV2`: [SystemLogLevel](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.SystemLogLevel.html) = SystemLogLevel.INFO — Sets the system log level for the function.

- `tenancyConfig`: [TenancyConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.TenancyConfig.html) — The tenancy configuration for the function.

  **Default:** Tenant isolation is not enabled

- `timeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.seconds(3) — The function execution time (in seconds) after which Lambda terminates the function.

  Because the execution time affects cost, set this value
  based on the function's expected execution time.

- `tracing`: [Tracing](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Tracing.html) = Tracing.Disabled — Enable AWS X-Ray Tracing for Lambda Function.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) — VPC network to place Lambda network interfaces.

  **Default:** Function is not placed within a VPC.

  Specify this if the Lambda function needs to access resources in a VPC.
  This is required when `vpcSubnets` is specified.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Where to place the network interfaces within the VPC.

  **Default:** the Vpc default strategy if not specified

  This requires `vpc` to be specified in order for interfaces to actually be
  placed in the subnets. If `vpc` is not specify, this will raise an error.

  Note: Internet access for Lambda Functions requires a NAT Gateway, so picking
  public subnets is not allowed (unless `allowPublicSubnet` is set to `true`).
