# CapacityProvider

A Lambda capacity provider that manages compute resources for Lambda functions.

Extends: Construct › Resource › CapacityProvider
Implements: IResource, ICapacityProvider, IEnvironmentAware, ICapacityProviderRef, IConstruct, IDependable

- CloudFormation: [`AWS::Lambda::CapacityProvider`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-lambda-capacityprovider.html)
- L1 type: [`CfnCapacityProvider`](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.CfnCapacityProvider.html)
- Source: [`aws-lambda/lib/capacity-provider.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-lambda/lib/capacity-provider.ts#L398)
- Type last changed: v2.235.0 · 15 Jan 2026

## Example

```ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as logs from 'aws-cdk-lib/aws-logs';

const vpc = new ec2.Vpc(this, 'MyVpc');
const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', { vpc });

const capacityProvider = new lambda.CapacityProvider(this, 'MyCapacityProvider', {
  subnets: vpc.privateSubnets,
  securityGroups: [securityGroup],
  logGroup: new logs.LogGroup(this, 'CpLogs', {
    logGroupName: '/aws/lambda/capacity-provider/my-cp',
  }),
  systemLogLevel: lambda.SystemLogLevel.DEBUG,
});
```

## Initializer

```ts
new CapacityProvider(scope: Construct, id: string, props: CapacityProviderProps)
```

## Construct Props

- `architectures`: [Architecture](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Architecture.html)[] — The instruction set architecture required for compute instances.

  **Default:** No architecture constraints specified

  Only one architecture can be specified per capacity provider.

- `capacityProviderName`: string — The name of the capacity provider.

  **Default:** AWS CloudFormation generates a unique physical ID and uses that ID for the capacity provider's name.

  The name must be unique within the AWS account and region.

- `instanceTypeFilter`: [InstanceTypeFilter](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.InstanceTypeFilter.html) — Configuration for filtering instance types that the capacity provider can use.

  **Default:** No instance type filtering applied

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — The AWS Key Management Service (KMS) key used to encrypt data associated with the capacity provider.

  **Default:** No KMS key specified, uses an AWS-managed key instead

- `logGroup`: [ILogGroupRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_logs.ILogGroupRef.html) — The CloudWatch log group for capacity provider system logs.

  **Default:** Service creates a default log group at /aws/lambda/capacity-provider/<name>

- `maxVCpuCount`: number — The maximum number of vCPUs that the capacity provider can scale up to.

  **Default:** No maximum limit specified, service default is 400

- `operatorRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that the Lambda service assumes to manage the capacity provider.

  **Default:** A role will be generated containing the AWSLambdaManagedEC2ResourceOperator managed policy

- `propagateTags`: [PropagateTags](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.PropagateTags.html) — Configuration for tag propagation to managed resources (EC2 instances, ENIs, EBS volumes).

  **Default:** No tag propagation; tags are not propagated to managed resources.

  Use the static factory methods on `PropagateTags` to create:
  - `PropagateTags.none()` - Explicitly disable tag propagation
  - `PropagateTags.explicit(tags)` - Propagate specified tags

- `scalingOptions`: [ScalingOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ScalingOptions.html) — The options for scaling a capacity provider, including scaling policies.

  **Default:** The `Auto` option is applied by default

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] (required) — A list of security group IDs to associate with EC2 instances launched by the capacity provider.

  Up to 5 security groups can be specified.

- `subnets`: [ISubnet](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISubnet.html)[] (required) — A list of subnets where the capacity provider can launch EC2 instances.

  At least one subnet must be specified, and up to 16 subnets are supported.

- `systemLogLevel`: [SystemLogLevel](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.SystemLogLevel.html) — The level of detail for capacity provider system logs.

  **Default:** Service default applies (INFO)

## Properties

- `capacityProviderArn`: string — The Amazon Resource Name (ARN) of the capacity provider.

- `capacityProviderName`: string — The name of the capacity provider.

- `capacityProviderRef`: [CapacityProviderReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_lambda.CapacityProviderReference.html) — A reference to a CapacityProvider resource.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

## Methods

- `addFunction(func: IFunction, options?: CapacityProviderFunctionOptions): void` — Configures a Lambda function to use this capacity provider.

  **Parameters**

  - `func` — The Lambda function to configure.
  - `options` — Optional configuration for the function's capacity provider settings.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromCapacityProviderArn(scope: Construct, id: string, capacityProviderArn: string): ICapacityProvider` (static) — Import an existing capacity provider by ARN.

  **Parameters**

  - `scope` — The parent construct.
  - `id` — The construct ID.
  - `capacityProviderArn` — The ARN of the capacity provider to import.

- `fromCapacityProviderAttributes(scope: Construct, id: string, attrs: CapacityProviderAttributes): ICapacityProvider` (static) — Import an existing capacity provider using its attributes.

  **Parameters**

  - `scope` — The parent construct.
  - `id` — The construct ID.
  - `attrs` — The capacity provider attributes.

- `fromCapacityProviderName(scope: Construct, id: string, capacityProviderName: string): ICapacityProvider` (static) — Import an existing capacity provider by name.

  **Parameters**

  - `scope` — The parent construct.
  - `id` — The construct ID.
  - `capacityProviderName` — The name of the capacity provider to import.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
