CapacityProvider
- class aws_cdk.aws_lambda.CapacityProvider(scope, id, *, security_groups, subnets, architectures=None, capacity_provider_name=None, instance_type_filter=None, kms_key=None, max_v_cpu_count=None, operator_role=None, scaling_options=None)
Bases:
ResourceA Lambda capacity provider that manages compute resources for Lambda functions.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_ec2 as ec2 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], scaling_options=lambda_.ScalingOptions.manual([ lambda_.TargetTrackingScalingPolicy.cpu_utilization(70) ]) )
Creates a new Lambda capacity provider.
- Parameters:
scope (
Construct) – The parent construct.id (
str) – The construct ID.security_groups (
Sequence[ISecurityGroup]) – 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 (
Sequence[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 (
Optional[Sequence[Architecture]]) – The instruction set architecture required for compute instances. Only one architecture can be specified per capacity provider. Default: - No architecture constraints specifiedcapacity_provider_name (
Optional[str]) – The name of the capacity provider. The name must be unique within the AWS account and region. Default: - AWS CloudFormation generates a unique physical ID and uses that ID for the capacity provider’s name.instance_type_filter (
Optional[InstanceTypeFilter]) – Configuration for filtering instance types that the capacity provider can use. Default: - No instance type filtering appliedkms_key (
Optional[IKey]) – 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 insteadmax_v_cpu_count (
Union[int,float,None]) – The maximum number of vCPUs that the capacity provider can scale up to. Default: - No maximum limit specified, service default is 400operator_role (
Optional[IRole]) – The IAM role that the Lambda service assumes to manage the capacity provider. Default: - A role will be generated containing the AWSLambdaManagedEC2ResourceOperator managed policyscaling_options (
Optional[ScalingOptions]) – The options for scaling a capacity provider, including scaling policies. Default: - TheAutooption is applied by default
Methods
- add_function(func, *, execution_environment_memory_gib_per_v_cpu=None, latest_published_scaling_config=None, per_execution_environment_max_concurrency=None, publish_to_latest_published=None)
Configures a Lambda function to use this capacity provider.
- Parameters:
func (
IFunction) – The Lambda function to configure.execution_environment_memory_gib_per_v_cpu (
Union[int,float,None]) – Specifies the execution environment memory per VCPU, in GiB. Default: 2.0latest_published_scaling_config (
Union[LatestPublishedScalingConfig,Dict[str,Any],None]) – The scaling options that are applied to the $LATEST.PUBLISHED version. Default: - No scaling limitations are applied to the $LATEST.PUBLISHED version.per_execution_environment_max_concurrency (
Union[int,float,None]) – Specifies the maximum number of concurrent invokes a single execution environment can handle. Default: Maximum is set to 10publish_to_latest_published (
Optional[bool]) – A boolean determining whether or not to automatically publish to the $LATEST.PUBLISHED version. Default: - True
- Return type:
None
- apply_removal_policy(policy)
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).- Parameters:
policy (
RemovalPolicy)- Return type:
None
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- PROPERTY_INJECTION_ID = 'aws-cdk-lib.aws-lambda.CapacityProvider'
- capacity_provider_arn
The Amazon Resource Name (ARN) of the capacity provider.
- capacity_provider_name
The name of the capacity provider.
- env
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
The tree node.
- stack
The stack in which this resource is defined.
Static Methods
- classmethod from_capacity_provider_arn(scope, id, capacity_provider_arn)
Import an existing capacity provider by ARN.
- Parameters:
scope (
Construct) – The parent construct.id (
str) – The construct ID.capacity_provider_arn (
str) – The ARN of the capacity provider to import.
- Return type:
- classmethod from_capacity_provider_attributes(scope, id, *, capacity_provider_arn)
Import an existing capacity provider using its attributes.
- Parameters:
scope (
Construct) – The parent construct.id (
str) – The construct ID.capacity_provider_arn (
str) – The Amazon Resource Name (ARN) of the capacity provider. Format: arn::lambda:::capacity-provider:
- Return type:
- classmethod from_capacity_provider_name(scope, id, capacity_provider_name)
Import an existing capacity provider by name.
- Parameters:
scope (
Construct) – The parent construct.id (
str) – The construct ID.capacity_provider_name (
str) – The name of the capacity provider to import.
- Return type:
- classmethod is_construct(x)
Checks if
xis a construct.Use this method instead of
instanceofto properly detectConstructinstances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructslibrary on disk are seen as independent, completely different libraries. As a consequence, the classConstructin each copy of theconstructslibrary is seen as a different class, and an instance of one class will not test asinstanceofthe other class.npm installwill not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructslibrary can be accidentally installed, andinstanceofwill behave unpredictably. It is safest to avoid usinginstanceof, and using this type-testing method instead.- Parameters:
x (
Any) – Any object.- Return type:
bool- Returns:
true if
xis an object created from a class which extendsConstruct.
- classmethod is_owned_resource(construct)
Returns true if the construct was created by CDK, and false otherwise.
- Parameters:
construct (
IConstruct)- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct)- Return type:
bool