Skip to content
v2.274.0

CapacityProvider L2 construct ​

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

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,
});
python
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_logs as logs


vpc = ec2.Vpc(self, "MyVpc")
security_group = ec2.SecurityGroup(self, "SecurityGroup", vpc=vpc)

capacity_provider = lambda_.CapacityProvider(self, "MyCapacityProvider",
    subnets=vpc.private_subnets,
    security_groups=[security_group],
    log_group=logs.LogGroup(self, "CpLogs",
        log_group_name="/aws/lambda/capacity-provider/my-cp"
    ),
    system_log_level=lambda_.SystemLogLevel.DEBUG
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.logs.*;


Vpc vpc = new Vpc(this, "MyVpc");
SecurityGroup securityGroup = SecurityGroup.Builder.create(this, "SecurityGroup").vpc(vpc).build();

CapacityProvider capacityProvider = CapacityProvider.Builder.create(this, "MyCapacityProvider")
        .subnets(vpc.getPrivateSubnets())
        .securityGroups(List.of(securityGroup))
        .logGroup(LogGroup.Builder.create(this, "CpLogs")
                .logGroupName("/aws/lambda/capacity-provider/my-cp")
                .build())
        .systemLogLevel(SystemLogLevel.DEBUG)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.Logs;


var vpc = new Vpc(this, "MyVpc");
var securityGroup = new SecurityGroup(this, "SecurityGroup", new SecurityGroupProps { Vpc = vpc });

var capacityProvider = new CapacityProvider(this, "MyCapacityProvider", new CapacityProviderProps {
    Subnets = vpc.PrivateSubnets,
    SecurityGroups = new [] { securityGroup },
    LogGroup = new LogGroup(this, "CpLogs", new LogGroupProps {
        LogGroupName = "/aws/lambda/capacity-provider/my-cp"
    }),
    SystemLogLevel = SystemLogLevel.DEBUG
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import logs "github.com/aws/aws-cdk-go/awscdk"


vpc := ec2.NewVpc(this, jsii.String("MyVpc"))
securityGroup := ec2.NewSecurityGroup(this, jsii.String("SecurityGroup"), &SecurityGroupProps{
	Vpc: Vpc,
})

capacityProvider := lambda.NewCapacityProvider(this, jsii.String("MyCapacityProvider"), &CapacityProviderProps{
	Subnets: vpc.PrivateSubnets,
	SecurityGroups: []ISecurityGroup{
		securityGroup,
	},
	LogGroup: logs.NewLogGroup(this, jsii.String("CpLogs"), &LogGroupProps{
		LogGroupName: jsii.String("/aws/lambda/capacity-provider/my-cp"),
	}),
	SystemLogLevel: lambda.SystemLogLevel_DEBUG,
})

Initializer ​

ts
new CapacityProvider(scope: Construct, id: string, props: CapacityProviderProps)
python
CapacityProvider(scope: Construct, id: str, props: CapacityProviderProps)
java
new CapacityProvider(Construct scope, String id, CapacityProviderProps props)
csharp
new CapacityProvider(Construct scope, string id, CapacityProviderProps props)
go
NewCapacityProvider(Scope Construct, Id *string, Props CapacityProviderProps)

Construct Props ​

architecturesArchitecture[]architecturestyping.List[Architecture]architecturesList<Architecture>ArchitecturesArchitecture[]Architectures*[]Architecture= No architecture constraints spec…#
The instruction set architecture required for compute instances.

Only one architecture can be specified per capacity provider.

default

Default: No architecture constraints specified

capacityProviderNamestringcapacity_provider_namestrcapacityProviderNameStringCapacityProviderNamestringCapacityProviderName*string= AWS CloudFormation generates a u…#
The name of the capacity provider.

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

default

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

instanceTypeFilterInstanceTypeFilterinstance_type_filterInstanceTypeFilterinstanceTypeFilterInstanceTypeFilterInstanceTypeFilterInstanceTypeFilterInstanceTypeFilterInstanceTypeFilter= No instance type filtering appli…#
Configuration for filtering instance types that the capacity provider can use.
default

Default: No instance type filtering applied

kmsKeyIKeykms_keyIKeykmsKeyIKeyKmsKeyIKeyKmsKeyIKey= No KMS key specified, uses an AW…#
The AWS Key Management Service (KMS) key used to encrypt data associated with the capacity provider.
default

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

logGroupILogGroupReflog_groupILogGroupReflogGroupILogGroupRefLogGroupILogGroupRefLogGroupILogGroupRef= Service creates a default log gr…#
The CloudWatch log group for capacity provider system logs.
default

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

maxVCpuCountnumbermax_v_cpu_countint | floatmaxVCpuCountNumberMaxVCpuCountdoubleMaxVCpuCount*float64= No maximum limit specified, serv…#
The maximum number of vCPUs that the capacity provider can scale up to.
default

Default: No maximum limit specified, service default is 400

operatorRoleIRoleoperator_roleIRoleoperatorRoleIRoleOperatorRoleIRoleOperatorRoleIRole= A role will be generated contain…#
The IAM role that the Lambda service assumes to manage the capacity provider.
default

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

propagateTagsPropagateTagspropagate_tagsPropagateTagspropagateTagsPropagateTagsPropagateTagsPropagateTagsPropagateTagsPropagateTags= No tag propagation; tags are not…#
Configuration for tag propagation to managed resources (EC2 instances, ENIs, EBS volumes).

Use the static factory methods on PropagateTags to create:

  • PropagateTags.none() - Explicitly disable tag propagation
  • PropagateTags.explicit(tags) - Propagate specified tags
default

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

scalingOptionsScalingOptionsscaling_optionsScalingOptionsscalingOptionsScalingOptionsScalingOptionsScalingOptionsScalingOptionsScalingOptions= The `Auto` option is applied by …#
The options for scaling a capacity provider, including scaling policies.
default

Default: The Auto option is applied by default

securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGrouprequired#
A list of security group IDs to associate with EC2 instances launched by the capacity provider.

Up to 5 security groups can be specified.

subnetsISubnet[]subnetstyping.List[ISubnet]subnetsList<ISubnet>SubnetsISubnet[]Subnets*[]ISubnetrequired#
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.

systemLogLevelSystemLogLevelsystem_log_levelSystemLogLevelsystemLogLevelSystemLogLevelSystemLogLevelSystemLogLevelSystemLogLevelSystemLogLevel= Service default applies (INFO)#
The level of detail for capacity provider system logs.

Properties ​

capacityProviderArnstringcapacity_provider_arnstrcapacityProviderArnStringCapacityProviderArnstringCapacityProviderArn*stringrequired#
The Amazon Resource Name (ARN) of the capacity provider.
capacityProviderNamestringcapacity_provider_namestrcapacityProviderNameStringCapacityProviderNamestringCapacityProviderName*stringrequired#
The name of the capacity provider.
capacityProviderRefCapacityProviderReferencecapacity_provider_refCapacityProviderReferencecapacityProviderRefCapacityProviderReferenceCapacityProviderRefCapacityProviderReferenceCapacityProviderRefCapacityProviderReferencerequired#
A reference to a CapacityProvider resource.
The environment this resource belongs to.
notes

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.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addFunction(func: IFunction, options?: CapacityProviderFunctionOptions): voiddef add_function(self, func: IFunction, options: typing.Optional[CapacityProviderFunctionOptions] = None) -> Nonepublic void addFunction(IFunction func, CapacityProviderFunctionOptions options)public void AddFunction(IFunction func, CapacityProviderFunctionOptions? options = null)func AddFunction(Func IFunction, Options CapacityProviderFunctionOptions)#
Configures a Lambda function to use this capacity provider.
2 parameters

Parameters

  • funcfuncfuncfuncFunc — The Lambda function to configure.
  • optionsoptionsoptionsoptionsOptions — Optional configuration for the function's capacity provider settings.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

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

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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@staticmethod def from_capacity_provider_arn(scope: Construct, id: str, capacity_provider_arn: str) -> ICapacityProviderpublic static ICapacityProvider fromCapacityProviderArn(Construct scope, String id, String capacityProviderArn)public static ICapacityProvider FromCapacityProviderArn(Construct scope, string id, string capacityProviderArn)func FromCapacityProviderArn(Scope Construct, Id *string, CapacityProviderArn *string) ICapacityProviderstatic#
Import an existing capacity provider by ARN.
3 parameters

Parameters

  • scopescopescopescopeScope — The parent construct.
  • ididididId — The construct ID.
  • capacityProviderArncapacity_provider_arncapacityProviderArncapacityProviderArnCapacityProviderArn — The ARN of the capacity provider to import.
fromCapacityProviderAttributes(scope: Construct, id: string, attrs: CapacityProviderAttributes): ICapacityProvider@staticmethod def from_capacity_provider_attributes(scope: Construct, id: str, attrs: CapacityProviderAttributes) -> ICapacityProviderpublic static ICapacityProvider fromCapacityProviderAttributes(Construct scope, String id, CapacityProviderAttributes attrs)public static ICapacityProvider FromCapacityProviderAttributes(Construct scope, string id, CapacityProviderAttributes attrs)func FromCapacityProviderAttributes(Scope Construct, Id *string, Attrs CapacityProviderAttributes) ICapacityProviderstatic#
Import an existing capacity provider using its attributes.
3 parameters

Parameters

  • scopescopescopescopeScope — The parent construct.
  • ididididId — The construct ID.
  • attrsattrsattrsattrsAttrs — The capacity provider attributes.
fromCapacityProviderName(scope: Construct, id: string, capacityProviderName: string): ICapacityProvider@staticmethod def from_capacity_provider_name(scope: Construct, id: str, capacity_provider_name: str) -> ICapacityProviderpublic static ICapacityProvider fromCapacityProviderName(Construct scope, String id, String capacityProviderName)public static ICapacityProvider FromCapacityProviderName(Construct scope, string id, string capacityProviderName)func FromCapacityProviderName(Scope Construct, Id *string, CapacityProviderName *string) ICapacityProviderstatic#
Import an existing capacity provider by name.
3 parameters

Parameters

  • scopescopescopescopeScope — The parent construct.
  • ididididId — The construct ID.
  • capacityProviderNamecapacity_provider_namecapacityProviderNamecapacityProviderNameCapacityProviderName — The name of the capacity provider to import.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.