# CapacityProviderFunctionOptions

Options for creating a function associated with a capacity provider.

- Source: [`aws-lambda/lib/capacity-provider.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda/lib/capacity-provider.ts#L338)
- Type last changed: v2.231.0 · 1 Dec 2025

## Example

TypeScript:

```ts
declare const capacityProvider: lambda.CapacityProvider;

const fn = new lambda.Function(this, 'MyFunction', {
  // Runtime must be equal to or newer than NODEJS_LATEST
  runtime: lambda.Runtime.NODEJS_LATEST,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
});

// Associate the function with the capacity provider
capacityProvider.addFunction(fn, {
  perExecutionEnvironmentMaxConcurrency: 10,
  executionEnvironmentMemoryGiBPerVCpu: 4,
});
```

Python:

```python
# capacity_provider: lambda.CapacityProvider

fn = lambda_.Function(self, "MyFunction",
    # Runtime must be equal to or newer than NODEJS_LATEST
    runtime=lambda_.Runtime.NODEJS_LATEST,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler"))
)

# Associate the function with the capacity provider
capacity_provider.add_function(fn,
    per_execution_environment_max_concurrency=10,
    execution_environment_memory_gi_b_per_v_cpu=4
)
```

Java:

```java
CapacityProvider capacityProvider;

Function fn = Function.Builder.create(this, "MyFunction")
        // Runtime must be equal to or newer than NODEJS_LATEST
        .runtime(Runtime.NODEJS_LATEST)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "lambda-handler")))
        .build();

// Associate the function with the capacity provider
capacityProvider.addFunction(fn, CapacityProviderFunctionOptions.builder()
        .perExecutionEnvironmentMaxConcurrency(10)
        .executionEnvironmentMemoryGiBPerVCpu(4)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
CapacityProvider capacityProvider;

var fn = new Function(this, "MyFunction", new FunctionProps {
    // Runtime must be equal to or newer than NODEJS_LATEST
    Runtime = Runtime.NODEJS_LATEST,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "lambda-handler"))
});

// Associate the function with the capacity provider
capacityProvider.AddFunction(fn, new CapacityProviderFunctionOptions {
    PerExecutionEnvironmentMaxConcurrency = 10,
    ExecutionEnvironmentMemoryGiBPerVCpu = 4
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var capacityProvider CapacityProvider

fn := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	// Runtime must be equal to or newer than NODEJS_LATEST
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("lambda-handler"))),
})

// Associate the function with the capacity provider
capacityProvider.AddFunction(fn, &CapacityProviderFunctionOptions{
	PerExecutionEnvironmentMaxConcurrency: jsii.Number(10),
	ExecutionEnvironmentMemoryGiBPerVCpu: jsii.Number(4),
})
```

## Properties

- `executionEnvironmentMemoryGiBPerVCpu`: number = 2.0 — Specifies the execution environment memory per VCPU, in GiB.

- `latestPublishedScalingConfig`: [LatestPublishedScalingConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LatestPublishedScalingConfig.html) — The scaling options that are applied to the $LATEST.PUBLISHED version.

  **Default:** No scaling limitations are applied to the $LATEST.PUBLISHED version.

- `perExecutionEnvironmentMaxConcurrency`: number — Specifies the maximum number of concurrent invokes a single execution environment can handle.

  **Default:** Maximum is set to 10

- `publishToLatestPublished`: boolean = True — A boolean determining whether or not to automatically publish to the $LATEST.PUBLISHED version.
