Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ def test_function_with_capacity_provider_default_role(self):
"AdvancedCapacityProvider should use the correct KMS key",
)

telemetry_config = advanced_cp_config.get("TelemetryConfig")
self.assertIsNotNone(telemetry_config, "AdvancedCapacityProvider should have TelemetryConfig")
logging_config = telemetry_config.get("LoggingConfig")
self.assertIsNotNone(logging_config, "AdvancedCapacityProvider should have LoggingConfig")
self.assertEqual(
logging_config.get("SystemLogLevel"), "DEBUG", "AdvancedCapacityProvider should have SystemLogLevel DEBUG"
)

def get_function_capacity_provider_config(self, function_name, alias_name=None):
lambda_client = self.client_provider.lambda_client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Resources:
MaxVCpuCount: 64
AverageCPUUtilization: 70
KmsKeyArn: !Ref KMSKeyArn
LoggingConfig:
SystemLogLevel: DEBUG
Tags:
Environment: Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class Properties(BaseModel):
# Uses custom ScalingConfig class because SAM renames construct (CapacityProviderScalingConfig→ScalingConfig)
ScalingConfig: ScalingConfig | None = properties("ScalingConfig")

# Optional logging configuration - maps to CFN TelemetryConfig.LoggingConfig
LoggingConfig: PassThroughProp | None = passthrough_prop(
PROPERTIES_STEM,
"LoggingConfig",
["AWS::Lambda::CapacityProvider.CapacityProviderLoggingConfig"],
)

KmsKeyArn: PassThroughProp | None = passthrough_prop(
PROPERTIES_STEM,
"KmsKeyArn",
Expand Down Expand Up @@ -113,6 +120,14 @@ class Globals(BaseModel):
# Uses custom ScalingConfig class because SAM renames construct (CapacityProviderScalingConfig→ScalingConfig)
ScalingConfig: ScalingConfig | None = properties("ScalingConfig")

# Global logging configuration - can be inherited by capacity providers if not overridden
# Global logging configuration - can be inherited by capacity providers
LoggingConfig: PassThroughProp | None = passthrough_prop(
PROPERTIES_STEM,
"LoggingConfig",
["AWS::Lambda::CapacityProvider.CapacityProviderLoggingConfig"],
)

KmsKeyArn: PassThroughProp | None = passthrough_prop(
PROPERTIES_STEM,
"KmsKeyArn",
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/internal/schema_source/sam-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,9 @@
"CapacityProviderName": "The name of the capacity provider. This name must be unique within your AWS account and region. \n*Type*: String \n*Required*: No \n*CloudFormation compatibility*: This property is passed directly to the [`CapacityProviderName`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-capacityprovidername) property of an `AWS::Lambda::CapacityProvider` resource.",
"InstanceRequirements": "Specifications for the types of compute instances that the capacity provider can use. This includes architecture requirements and `allowed` or `excluded` instance types. \n*Type*: [InstanceRequirements](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-capacityprovider-instancerequirements.html) \n*Required*: No \n*CloudFormation compatibility*: This property is passed directly to the [`InstanceRequirements`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-instancerequirements) property of an `AWS::Lambda::CapacityProvider` resource.",
"KmsKeyArn": "The ARN of the AWS KMS key used to encrypt data at rest and in transit for the capacity provider. \n*Type*: String \n*Required*: No \n*CloudFormation compatibility*: This property is passed directly to the [`KmsKeyArn`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-kmskeyarn) property of an `AWS::Lambda::CapacityProvider` resource.",
"LogGroup": "TODO",
Comment thread
vicheey marked this conversation as resolved.
"LoggingConfig": "TODO",
"SystemLogLevel": "TODO",
"OperatorRole": "The ARN of the operator role for Lambda with permissions to create and manage Amazon EC2 instances and related resources in the customer account. If not provided, AWS SAM automatically generates a role with the necessary permissions. \n*Type*: String \n*Required*: No \n*CloudFormation compatibility*: This property is passed directly to the [`CapacityProviderOperatorRoleArn`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityproviderpermissionsconfig.html#cfn-lambda-capacityprovider-capacityproviderpermissionsconfig-capacityprovideroperatorrolearn) property of [`PermissionsConfig`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-permissionsconfig) of an `AWS::Lambda::CapacityProvider` resource.",
"PropagateTags": "Indicates whether or not to pass tags from the Tags property to your `AWS::Serverless::CapacityProvider` generated resources. Set this to `True` to propagate tags in your generated resources. \n*Type*: Boolean \n*Required*: No \n*CloudFormation compatibility*: This property is unique to AWS SAM and doesn't have an CloudFormation equivalent.",
"ScalingConfig": "The scaling configuration for the capacity provider. Defines how the capacity provider scales Amazon EC2 instances based on demand. \n*Type*: [ScalingConfig](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-capacityprovider-scalingconfig.html) \n*Required*: No \n*CloudFormation compatibility*: This property is passed directly to the [`CapacityProviderScalingConfig`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig) property of an `AWS::Lambda::CapacityProvider` resource.",
Expand Down
6 changes: 6 additions & 0 deletions samtranslator/model/capacity_provider/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, logical_id: str, **kwargs: Any) -> None:
- instance_requirements: Instance type requirements
- scaling_config: Auto-scaling configuration
- kms_key_arn: KMS key ARN for encryption
- logging_config: Logging configuration (SAM LoggingConfig, wrapped to CFN TelemetryConfig)
- depends_on: Resources this capacity provider depends on
- resource_attributes: Resource attributes to add to capacity provider
- passthrough_resource_attributes: Resource attributes to pass to child resources
Expand All @@ -45,6 +46,7 @@ def __init__(self, logical_id: str, **kwargs: Any) -> None:
self.instance_requirements = kwargs.get("instance_requirements") or {}
self.scaling_config = kwargs.get("scaling_config") or {}
self.kms_key_arn = kwargs.get("kms_key_arn")
self.logging_config = kwargs.get("logging_config")
self.depends_on = kwargs.get("depends_on")
self.resource_attributes = kwargs.get("resource_attributes")
self.passthrough_resource_attributes = kwargs.get("passthrough_resource_attributes")
Expand Down Expand Up @@ -111,6 +113,10 @@ def _create_capacity_provider(self) -> LambdaCapacityProvider:
if self.kms_key_arn:
capacity_provider.KmsKeyArn = self.kms_key_arn

# Set TelemetryConfig - wraps SAM LoggingConfig into CFN TelemetryConfig.LoggingConfig
if self.logging_config:
capacity_provider.TelemetryConfig = {"LoggingConfig": self.logging_config}

# Pass through resource attributes
if self.passthrough_resource_attributes:
for attr_name, attr_value in self.passthrough_resource_attributes.items():
Expand Down
2 changes: 2 additions & 0 deletions samtranslator/model/capacity_provider/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LambdaCapacityProvider(Resource):
"InstanceRequirements": GeneratedProperty(),
"CapacityProviderScalingConfig": GeneratedProperty(),
"KmsKeyArn": GeneratedProperty(),
"TelemetryConfig": GeneratedProperty(),
}

CapacityProviderName: Intrinsicable[str] | None
Expand All @@ -32,6 +33,7 @@ class LambdaCapacityProvider(Resource):
InstanceRequirements: dict[str, Any] | None
CapacityProviderScalingConfig: dict[str, Any] | None
KmsKeyArn: Intrinsicable[str] | None
TelemetryConfig: dict[str, Any] | None

runtime_attrs = {
"name": lambda self: ref(self.logical_id),
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ class SamCapacityProvider(SamResourceMacro):
"InstanceRequirements": Property(False, IS_DICT),
"ScalingConfig": Property(False, IS_DICT),
"KmsKeyArn": Property(False, one_of(IS_STR, IS_DICT)),
"LoggingConfig": Property(False, IS_DICT),
}

CapacityProviderName: Intrinsicable[str] | None
Expand All @@ -1562,6 +1563,7 @@ class SamCapacityProvider(SamResourceMacro):
InstanceRequirements: dict[str, Any] | None
ScalingConfig: dict[str, Any] | None
KmsKeyArn: Intrinsicable[str] | None
LoggingConfig: dict[str, Any] | None

# Validation rules
__validation_rules__ = [
Expand Down Expand Up @@ -1596,6 +1598,7 @@ def to_cloudformation(self, **kwargs: Any) -> list[Resource]:
),
scaling_config=model.ScalingConfig.dict(exclude_none=True) if model.ScalingConfig else None,
kms_key_arn=passthrough_value(model.KmsKeyArn),
logging_config=model.LoggingConfig if model.LoggingConfig else None,
depends_on=self.depends_on,
resource_attributes=self.resource_attributes,
passthrough_resource_attributes=self.get_passthrough_resource_attributes(),
Expand Down
1 change: 1 addition & 0 deletions samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Globals:
"ScalingConfig",
"KmsKeyArn",
"PropagateTags",
"LoggingConfig",
],
SamResourceType.WebSocketApi.value: [
"AccessLogSettings",
Expand Down
Loading