Skip to content

Commit a45a711

Browse files
authored
fix: support KmsKeyArn in Serverless::CapacityProvider (#3860)
1 parent 6d61b22 commit a45a711

File tree

40 files changed

+82
-75
lines changed

40 files changed

+82
-75
lines changed

.cfnlintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ ignore_templates:
144144
- tests/translator/output/**/function_with_metrics_config.json
145145
- tests/translator/output/**/function_with_self_managed_kafka_and_schema_registry.json # cfnlint is not updated to recognize the SchemaRegistryConfig property
146146
- tests/translator/output/**/function_with_msk_with_schema_registry_config.json # cfnlint is not updated to recognize the SchemaRegistryConfig property
147-
- tests/translator/output/**/*capacity_provider*.json # TODO: Remove this once CFN updates
147+
- tests/translator/output/aws-*/*capacity_provider*.json # Ignore Capacity Provider test format in non-aws partitions
148148
- tests/translator/output/**/function_with_tenancy_config.json # cfnlint is not updated to recognize the TenancyConfig property
149149
- tests/translator/output/**/function_with_tenancy_and_api_event.json # cfnlint is not updated to recognize the TenancyConfig property
150150
- tests/translator/output/**/function_with_tenancy_and_httpapi_event.json # cfnlint is not updated to recognize the TenancyConfig property

samtranslator/internal/schema_source/aws_serverless_capacity_provider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ class Properties(BaseModel):
8888
# TODO: Change back to passthrough_prop after CloudFormation schema is updated with AWS::Lambda::CapacityProvider
8989
# Optional KMS key ARN - passes through directly to CFN for encryption configuration
9090
# Uses PassThroughProp because it's a direct 1:1 mapping with no SAM transformation
91-
# KMSKeyArn: Optional[PassThroughProp] = passthrough_prop(
91+
# KmsKeyArn: Optional[PassThroughProp] = passthrough_prop(
9292
# PROPERTIES_STEM,
93-
# "KMSKeyArn",
94-
# ["AWS::Lambda::CapacityProvider", "Properties", "KMSKeyArn"],
93+
# "KmsKeyArn",
94+
# ["AWS::Lambda::CapacityProvider", "Properties", "KmsKeyArn"],
9595
# )
96-
KMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
96+
KmsKeyArn: Optional[PassThroughProp] # TODO: add documentation
9797

9898

9999
class Globals(BaseModel):
@@ -120,7 +120,7 @@ class Globals(BaseModel):
120120
# Uses custom ScalingConfig class because SAM renames construct (CapacityProviderScalingConfig→ScalingConfig)
121121
ScalingConfig: Optional[ScalingConfig] = properties("ScalingConfig")
122122

123-
KMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
123+
KmsKeyArn: Optional[PassThroughProp] # TODO: add documentation
124124

125125

126126
class Resource(ResourceAttributes):

samtranslator/model/capacity_provider/generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def _create_capacity_provider(self) -> LambdaCapacityProvider:
107107
if self.scaling_config:
108108
capacity_provider.CapacityProviderScalingConfig = self._transform_scaling_config()
109109

110-
# Set the KMSKeyArn if provided
110+
# Set the KmsKeyArn if provided
111111
if self.kms_key_arn:
112-
capacity_provider.KMSKeyArn = self.kms_key_arn
112+
capacity_provider.KmsKeyArn = self.kms_key_arn
113113

114114
# Pass through resource attributes
115115
if self.passthrough_resource_attributes:

samtranslator/model/capacity_provider/resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LambdaCapacityProvider(Resource):
2222
"Tags": GeneratedProperty(),
2323
"InstanceRequirements": GeneratedProperty(),
2424
"CapacityProviderScalingConfig": GeneratedProperty(),
25-
"KMSKeyArn": GeneratedProperty(),
25+
"KmsKeyArn": GeneratedProperty(),
2626
}
2727

2828
CapacityProviderName: Optional[Intrinsicable[str]]
@@ -31,7 +31,7 @@ class LambdaCapacityProvider(Resource):
3131
Tags: Optional[List[Dict[str, Any]]]
3232
InstanceRequirements: Optional[Dict[str, Any]]
3333
CapacityProviderScalingConfig: Optional[Dict[str, Any]]
34-
KMSKeyArn: Optional[Intrinsicable[str]]
34+
KmsKeyArn: Optional[Intrinsicable[str]]
3535

3636
runtime_attrs = {
3737
"name": lambda self: ref(self.logical_id),

samtranslator/model/sam_resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ class SamCapacityProvider(SamResourceMacro):
14681468
"PropagateTags": Property(False, IS_BOOL),
14691469
"InstanceRequirements": Property(False, IS_DICT),
14701470
"ScalingConfig": Property(False, IS_DICT),
1471-
"KMSKeyArn": Property(False, one_of(IS_STR, IS_DICT)),
1471+
"KmsKeyArn": Property(False, one_of(IS_STR, IS_DICT)),
14721472
}
14731473

14741474
CapacityProviderName: Optional[Intrinsicable[str]]
@@ -1478,7 +1478,7 @@ class SamCapacityProvider(SamResourceMacro):
14781478
PropagateTags: Optional[bool]
14791479
InstanceRequirements: Optional[Dict[str, Any]]
14801480
ScalingConfig: Optional[Dict[str, Any]]
1481-
KMSKeyArn: Optional[Intrinsicable[str]]
1481+
KmsKeyArn: Optional[Intrinsicable[str]]
14821482

14831483
# Validation rules
14841484
__validation_rules__ = [
@@ -1509,7 +1509,7 @@ def to_cloudformation(self, **kwargs: Any) -> List[Resource]:
15091509
model.InstanceRequirements.dict(exclude_none=True) if model.InstanceRequirements else None
15101510
),
15111511
scaling_config=model.ScalingConfig.dict(exclude_none=True) if model.ScalingConfig else None,
1512-
kms_key_arn=passthrough_value(model.KMSKeyArn),
1512+
kms_key_arn=passthrough_value(model.KmsKeyArn),
15131513
depends_on=self.depends_on,
15141514
resource_attributes=self.resource_attributes,
15151515
passthrough_resource_attributes=self.get_passthrough_resource_attributes(),

samtranslator/plugins/globals/globals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Globals:
110110
"Tags",
111111
"InstanceRequirements",
112112
"ScalingConfig",
113-
"KMSKeyArn",
113+
"KmsKeyArn",
114114
"PropagateTags",
115115
],
116116
}

samtranslator/schema/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278147,7 +278147,7 @@
278147278147
"markdownDescription": "Instance requirements for the capacity provider.\n*Type*: [InstanceRequirements](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-capacityprovider-instancerequirements.html)\n*Required*: No\n*AWS 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.",
278148278148
"title": "InstanceRequirements"
278149278149
},
278150-
"KMSKeyArn": {
278150+
"KmsKeyArn": {
278151278151
"$ref": "#/definitions/PassThroughProp"
278152278152
},
278153278153
"OperatorRole": {
@@ -278206,7 +278206,7 @@
278206278206
"markdownDescription": "Instance requirements for the capacity provider.\n*Type*: [InstanceRequirements](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-capacityprovider-instancerequirements.html)\n*Required*: No\n*AWS 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.",
278207278207
"title": "InstanceRequirements"
278208278208
},
278209-
"KMSKeyArn": {
278209+
"KmsKeyArn": {
278210278210
"$ref": "#/definitions/PassThroughProp"
278211278211
},
278212278212
"OperatorRole": {

schema_source/sam.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5138,7 +5138,7 @@
51385138
"markdownDescription": "Instance requirements for the capacity provider.\n*Type*: [InstanceRequirements](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-capacityprovider-instancerequirements.html)\n*Required*: No\n*AWS 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.",
51395139
"title": "InstanceRequirements"
51405140
},
5141-
"KMSKeyArn": {
5141+
"KmsKeyArn": {
51425142
"$ref": "#/definitions/PassThroughProp"
51435143
},
51445144
"OperatorRole": {
@@ -5197,7 +5197,7 @@
51975197
"markdownDescription": "Instance requirements for the capacity provider.\n*Type*: [InstanceRequirements](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-capacityprovider-instancerequirements.html)\n*Required*: No\n*AWS 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.",
51985198
"title": "InstanceRequirements"
51995199
},
5200-
"KMSKeyArn": {
5200+
"KmsKeyArn": {
52015201
"$ref": "#/definitions/PassThroughProp"
52025202
},
52035203
"OperatorRole": {

tests/model/capacity_provider/test_generators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_to_cloudformation_with_provided_permissions(self):
9696
properties["VpcConfig"], {"SubnetIds": ["subnet-123", "subnet-456"], "SecurityGroupIds": ["sg-123"]}
9797
)
9898
self.assertEqual(properties["PermissionsConfig"]["CapacityProviderOperatorRoleArn"], operator_role)
99-
self.assertEqual(properties["KMSKeyArn"], self.kms_key_arn)
99+
self.assertEqual(properties["KmsKeyArn"], self.kms_key_arn)
100100

101101
def test_to_cloudformation_with_auto_generated_permissions(self):
102102
"""Test to_cloudformation with auto-generated operator role"""

tests/model/capacity_provider/test_resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_properties(self):
3232
{"PredefinedMetricType": "LambdaCapacityProviderAverageCPUUtilization", "TargetValue": 70.0}
3333
],
3434
}
35-
capacity_provider.KMSKeyArn = "arn:aws:kms:us-west-2:123456789012:key/abcd1234-ab12-cd34-ef56-abcdef123456"
35+
capacity_provider.KmsKeyArn = "arn:aws:kms:us-west-2:123456789012:key/abcd1234-ab12-cd34-ef56-abcdef123456"
3636

3737
# Verify properties
3838
self.assertEqual(capacity_provider.CapacityProviderName, "test-provider")
@@ -64,7 +64,7 @@ def test_properties(self):
6464
},
6565
)
6666
self.assertEqual(
67-
capacity_provider.KMSKeyArn, "arn:aws:kms:us-west-2:123456789012:key/abcd1234-ab12-cd34-ef56-abcdef123456"
67+
capacity_provider.KmsKeyArn, "arn:aws:kms:us-west-2:123456789012:key/abcd1234-ab12-cd34-ef56-abcdef123456"
6868
)
6969

7070
def test_runtime_attributes(self):

0 commit comments

Comments
 (0)