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: Resource

A 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 specified

  • capacity_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 applied

  • kms_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 instead

  • max_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 400

  • operator_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 policy

  • scaling_options (Optional[ScalingOptions]) – The options for scaling a capacity provider, including scaling policies. Default: - The Auto option 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.0

  • latest_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 10

  • publish_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:

ICapacityProvider

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:

ICapacityProvider

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:

ICapacityProvider

classmethod is_construct(x)

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) – Any object.

Return type:

bool

Returns:

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

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