class CapacityProvider (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.Lambda.CapacityProvider |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awslambda#CapacityProvider |
Java | software.amazon.awscdk.services.lambda.CapacityProvider |
Python | aws_cdk.aws_lambda.CapacityProvider |
TypeScript (source) | aws-cdk-lib » aws_lambda » CapacityProvider |
Implements
IConstruct, IDependable, IResource, IEnvironment, ICapacity
A Lambda capacity provider that manages compute resources for Lambda functions.
Example
import * as ec2 from 'aws-cdk-lib/aws-ec2';
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],
scalingOptions: lambda.ScalingOptions.manual([
lambda.TargetTrackingScalingPolicy.cpuUtilization(70),
]),
});
Initializer
new CapacityProvider(scope: Construct, id: string, props: CapacityProviderProps)
Parameters
- scope
Construct— The parent construct. - id
string— The construct ID. - props
Capacity— The capacity provider properties.Provider Props
Creates a new Lambda capacity provider.
Construct Props
| Name | Type | Description |
|---|---|---|
| security | ISecurity[] | A list of security group IDs to associate with EC2 instances launched by the capacity provider. |
| subnets | ISubnet[] | A list of subnets where the capacity provider can launch EC2 instances. |
| architectures? | Architecture[] | The instruction set architecture required for compute instances. |
| capacity | string | The name of the capacity provider. |
| instance | Instance | Configuration for filtering instance types that the capacity provider can use. |
| kms | IKey | The AWS Key Management Service (KMS) key used to encrypt data associated with the capacity provider. |
| max | number | The maximum number of vCPUs that the capacity provider can scale up to. |
| operator | IRole | The IAM role that the Lambda service assumes to manage the capacity provider. |
| scaling | Scaling | The options for scaling a capacity provider, including scaling policies. |
securityGroups
Type:
ISecurity[]
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
Type:
ISubnet[]
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.
architectures?
Type:
Architecture[]
(optional, default: No architecture constraints specified)
The instruction set architecture required for compute instances.
Only one architecture can be specified per capacity provider.
capacityProviderName?
Type:
string
(optional, default: AWS CloudFormation generates a unique physical ID and uses that
ID for the capacity provider's name.)
The name of the capacity provider.
The name must be unique within the AWS account and region.
instanceTypeFilter?
Type:
Instance
(optional, default: No instance type filtering applied)
Configuration for filtering instance types that the capacity provider can use.
kmsKey?
Type:
IKey
(optional, default: No KMS key specified, uses an AWS-managed key instead)
The AWS Key Management Service (KMS) key used to encrypt data associated with the capacity provider.
maxVCpuCount?
Type:
number
(optional, default: No maximum limit specified, service default is 400)
The maximum number of vCPUs that the capacity provider can scale up to.
operatorRole?
Type:
IRole
(optional, default: A role will be generated containing the AWSLambdaManagedEC2ResourceOperator managed policy)
The IAM role that the Lambda service assumes to manage the capacity provider.
scalingOptions?
Type:
Scaling
(optional, default: The Auto option is applied by default)
The options for scaling a capacity provider, including scaling policies.
Properties
| Name | Type | Description |
|---|---|---|
| capacity | string | The Amazon Resource Name (ARN) of the capacity provider. |
| capacity | string | The name of the capacity provider. |
| env | Resource | The environment this resource belongs to. |
| node | Node | The tree node. |
| stack | Stack | The stack in which this resource is defined. |
| static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
capacityProviderArn
Type:
string
The Amazon Resource Name (ARN) of the capacity provider.
capacityProviderName
Type:
string
The name of the capacity provider.
env
Type:
Resource
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
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
| Name | Description |
|---|---|
| add | Configures a Lambda function to use this capacity provider. |
| apply | Apply the given removal policy to this resource. |
| to | Returns a string representation of this construct. |
| static from | Import an existing capacity provider by ARN. |
| static from | Import an existing capacity provider using its attributes. |
| static from | Import an existing capacity provider by name. |
addFunction(func, options?)
public addFunction(func: IFunction, options?: CapacityProviderFunctionOptions): void
Parameters
- func
IFunction— The Lambda function to configure. - options
Capacity— Optional configuration for the function's capacity provider settings.Provider Function Options
Configures a Lambda function to use this capacity provider.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
RemovalPolicy
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).
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromCapacityProviderArn(scope, id, capacityProviderArn)
public static fromCapacityProviderArn(scope: Construct, id: string, capacityProviderArn: string): ICapacityProvider
Parameters
- scope
Construct— The parent construct. - id
string— The construct ID. - capacityProviderArn
string— The ARN of the capacity provider to import.
Returns
Import an existing capacity provider by ARN.
static fromCapacityProviderAttributes(scope, id, attrs)
public static fromCapacityProviderAttributes(scope: Construct, id: string, attrs: CapacityProviderAttributes): ICapacityProvider
Parameters
- scope
Construct— The parent construct. - id
string— The construct ID. - attrs
Capacity— The capacity provider attributes.Provider Attributes
Returns
Import an existing capacity provider using its attributes.
static fromCapacityProviderName(scope, id, capacityProviderName)
public static fromCapacityProviderName(scope: Construct, id: string, capacityProviderName: string): ICapacityProvider
Parameters
- scope
Construct— The parent construct. - id
string— The construct ID. - capacityProviderName
string— The name of the capacity provider to import.
Returns
Import an existing capacity provider by name.

.NET
Go
Java
Python
TypeScript (