CapacityProvider L2 construct
A Lambda capacity provider that manages compute resources for Lambda functions.
Example
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,
});
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
)
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();
// 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
});
// 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
new CapacityProvider(scope: Construct, id: string, props: CapacityProviderProps)
CapacityProvider(scope: Construct, id: str, props: CapacityProviderProps)
new CapacityProvider(Construct scope, String id, CapacityProviderProps props)
new CapacityProvider(Construct scope, string id, CapacityProviderProps props)
NewCapacityProvider(Scope Construct, Id *string, Props CapacityProviderProps)
Construct Props
architecturesArchitecture[]architecturestyping.List[Architecture]architecturesList<Architecture>ArchitecturesArchitecture[]Architectures*[]Architecture= No architecture constraints spec…#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 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…#default
Default: No instance type filtering applied
default
Default: No KMS key specified, uses an AWS-managed key instead
logGroupILogGroupReflog_groupILogGroupReflogGroupILogGroupRefLogGroupILogGroupRefLogGroupILogGroupRef= Service creates a default log gr…#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…#default
Default: No maximum limit specified, service default is 400
operatorRoleIRoleoperator_roleIRoleoperatorRoleIRoleOperatorRoleIRoleOperatorRoleIRole= A role will be generated contain…#default
Default: A role will be generated containing the AWSLambdaManagedEC2ResourceOperator managed policy
propagateTagsPropagateTagspropagate_tagsPropagateTagspropagateTagsPropagateTagsPropagateTagsPropagateTagsPropagateTagsPropagateTags= No tag propagation; tags are not…#Use the static factory methods on PropagateTags to create:
PropagateTags.none()- Explicitly disable tag propagationPropagateTags.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 …#default
Default: The Auto option is applied by default
securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGrouprequired#Up to 5 security groups can be specified.
subnetsISubnet[]subnetstyping.List[ISubnet]subnetsList<ISubnet>SubnetsISubnet[]Subnets*[]ISubnetrequired#At least one subnet must be specified, and up to 16 subnets are supported.
systemLogLevelSystemLogLevelsystem_log_levelSystemLogLevelsystemLogLevelSystemLogLevelSystemLogLevelSystemLogLevelSystemLogLevelSystemLogLevel= Service default applies (INFO)#Properties
capacityProviderArnstringcapacity_provider_arnstrcapacityProviderArnStringCapacityProviderArnstringCapacityProviderArn*stringrequired#capacityProviderNamestringcapacity_provider_namestrcapacityProviderNameStringCapacityProviderNamestringCapacityProviderName*stringrequired#capacityProviderRefCapacityProviderReferencecapacity_provider_refCapacityProviderReferencecapacityProviderRefCapacityProviderReferenceCapacityProviderRefCapacityProviderReferenceCapacityProviderRefCapacityProviderReferencerequired#envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#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.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#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)#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)#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)#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#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#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#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#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#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#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#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.