Skip to content

Commit a03307e

Browse files
authored
Merge pull request #3846 from aws/tmp/1763588423/main
Merge main to develop
2 parents a9a9465 + fede6be commit a03307e

File tree

39 files changed

+1673
-2
lines changed

39 files changed

+1673
-2
lines changed

.cfnlintrc.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ 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/**/function_with_tenancy_config.json # cfnlint is not updated to recognize the TenancyConfig property
148+
- tests/translator/output/**/function_with_tenancy_and_api_event.json # cfnlint is not updated to recognize the TenancyConfig property
149+
- tests/translator/output/**/function_with_tenancy_and_httpapi_event.json # cfnlint is not updated to recognize the TenancyConfig property
150+
- tests/translator/output/**/function_with_tenancy_config_global.json # cfnlint is not updated to recognize the TenancyConfig property
147151

148152
ignore_checks:
149153
- E2531 # Deprecated runtime; not relevant for transform tests
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"LogicalResourceId": "MyLambdaFunction",
4+
"ResourceType": "AWS::Lambda::Function"
5+
},
6+
{
7+
"LogicalResourceId": "MyLambdaFunctionRole",
8+
"ResourceType": "AWS::IAM::Role"
9+
}
10+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Resources:
2+
MyLambdaFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
Handler: index.handler
6+
Runtime: nodejs18.x
7+
CodeUri: ${codeuri}
8+
MemorySize: 128
9+
TenancyConfig:
10+
TenantIsolationMode: PER_TENANT
11+
Policies:
12+
- AWSLambdaRole
13+
- AmazonS3ReadOnlyAccess
14+
Metadata:
15+
SamTransformTest: true

integration/single/test_basic_function.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,24 @@ def _assert_invoke(self, lambda_client, function_name, qualifier=None, expected_
392392
def _verify_get_request(self, url, expected_text):
393393
response = self.verify_get_request_response(url, 200)
394394
self.assertEqual(response.text, expected_text)
395+
396+
# @skipIf(current_region_does_not_support([MULTI_TENANCY]), "Multi-tenancy is not supported in this testing region")
397+
@skipIf(True, "Multi-tenancy feature is not available to test yet")
398+
def test_basic_function_with_tenancy_config(self):
399+
"""
400+
Creates a basic lambda function with TenancyConfig
401+
"""
402+
self.create_and_verify_stack("single/basic_function_with_tenancy_config")
403+
404+
lambda_client = self.client_provider.lambda_client
405+
function_name = self.get_physical_id_by_type("AWS::Lambda::Function")
406+
407+
# Get function configuration
408+
function_config = lambda_client.get_function_configuration(FunctionName=function_name)
409+
410+
# Verify TenancyConfig is set correctly
411+
self.assertEqual(
412+
function_config["TenancyConfig"]["TenantIsolationMode"],
413+
"PER_TENANT",
414+
"Expected TenantIsolationMode to be PER_TENANT",
415+
)

samtranslator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.101.0"
1+
__version__ = "1.102.0"

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ class ScheduleV2Event(BaseModel):
522522
LoggingConfig = Optional[PassThroughProp] # TODO: add documentation
523523
RecursiveLoop = Optional[PassThroughProp]
524524
SourceKMSKeyArn = Optional[PassThroughProp]
525+
TenancyConfig = Optional[PassThroughProp]
525526

526527

527528
class Properties(BaseModel):
@@ -650,6 +651,7 @@ class Properties(BaseModel):
650651
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
651652
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
652653
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
654+
TenancyConfig: Optional[PassThroughProp] # TODO: add documentation
653655

654656

655657
class Globals(BaseModel):
@@ -710,6 +712,7 @@ class Globals(BaseModel):
710712
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
711713
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
712714
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
715+
TenancyConfig: Optional[PassThroughProp] # TODO: add documentation
713716

714717

715718
class Resource(ResourceAttributes):

samtranslator/model/lambda_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class LambdaFunction(Resource):
3636
"RuntimeManagementConfig": GeneratedProperty(),
3737
"LoggingConfig": GeneratedProperty(),
3838
"RecursiveLoop": GeneratedProperty(),
39+
"TenancyConfig": GeneratedProperty(),
3940
}
4041

4142
Code: Dict[str, Any]
@@ -64,6 +65,7 @@ class LambdaFunction(Resource):
6465
RuntimeManagementConfig: Optional[Dict[str, Any]]
6566
LoggingConfig: Optional[Dict[str, Any]]
6667
RecursiveLoop: Optional[str]
68+
TenancyConfig: Optional[Dict[str, Any]]
6769

6870
runtime_attrs = {"name": lambda self: ref(self.logical_id), "arn": lambda self: fnGetAtt(self.logical_id, "Arn")}
6971

samtranslator/model/sam_resources.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class SamFunction(SamResourceMacro):
184184
"LoggingConfig": PassThroughProperty(False),
185185
"RecursiveLoop": PassThroughProperty(False),
186186
"SourceKMSKeyArn": PassThroughProperty(False),
187+
"TenancyConfig": PassThroughProperty(False),
187188
}
188189

189190
FunctionName: Optional[Intrinsicable[str]]
@@ -228,6 +229,7 @@ class SamFunction(SamResourceMacro):
228229
LoggingConfig: Optional[Dict[str, Any]]
229230
RecursiveLoop: Optional[str]
230231
SourceKMSKeyArn: Optional[str]
232+
TenancyConfig: Optional[Dict[str, Any]]
231233

232234
event_resolver = ResourceTypeResolver(
233235
samtranslator.model.eventsources,
@@ -277,6 +279,8 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: P
277279
if self.DeadLetterQueue:
278280
self._validate_dlq(self.DeadLetterQueue)
279281

282+
self._validate_tenancy_config_compatibility()
283+
280284
lambda_function = self._construct_lambda_function(intrinsics_resolver)
281285
resources.append(lambda_function)
282286

@@ -572,6 +576,37 @@ def _get_resolved_alias_name(
572576

573577
return resolved_alias_name
574578

579+
def _validate_tenancy_config_compatibility(self) -> None:
580+
if not self.TenancyConfig:
581+
return
582+
583+
if self.ProvisionedConcurrencyConfig:
584+
raise InvalidResourceException(
585+
self.logical_id,
586+
"Provisioned concurrency is not supported for functions enabled with tenancy configuration.",
587+
)
588+
589+
if self.FunctionUrlConfig:
590+
raise InvalidResourceException(
591+
self.logical_id,
592+
"Function URL is not supported for functions enabled with tenancy configuration.",
593+
)
594+
595+
if self.SnapStart:
596+
raise InvalidResourceException(
597+
self.logical_id,
598+
"SnapStart is not supported for functions enabled with tenancy configuration.",
599+
)
600+
601+
if self.Events:
602+
for event in self.Events.values():
603+
event_type = event.get("Type")
604+
if event_type not in ["Api", "HttpApi"]:
605+
raise InvalidResourceException(
606+
self.logical_id,
607+
f"Event source '{event_type}' is not supported for functions enabled with tenancy configuration. Only Api and HttpApi event sources are supported.",
608+
)
609+
575610
def _construct_lambda_function(self, intrinsics_resolver: IntrinsicsResolver) -> LambdaFunction:
576611
"""Constructs and returns the Lambda function.
577612
@@ -618,6 +653,7 @@ def _construct_lambda_function(self, intrinsics_resolver: IntrinsicsResolver) ->
618653

619654
lambda_function.RuntimeManagementConfig = self.RuntimeManagementConfig # type: ignore[attr-defined]
620655
lambda_function.LoggingConfig = self.LoggingConfig
656+
lambda_function.TenancyConfig = self.TenancyConfig
621657
lambda_function.RecursiveLoop = self.RecursiveLoop
622658
self._validate_package_type(lambda_function)
623659
return lambda_function

samtranslator/plugins/globals/globals.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Globals:
5656
"LoggingConfig",
5757
"RecursiveLoop",
5858
"SourceKMSKeyArn",
59+
"TenancyConfig",
5960
],
6061
# Everything except
6162
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
@@ -101,7 +102,12 @@ class Globals:
101102
}
102103
# unreleased_properties *must be* part of supported_properties too
103104
unreleased_properties: Dict[str, List[str]] = {
104-
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop", "SourceKMSKeyArn"],
105+
SamResourceType.Function.value: [
106+
"RuntimeManagementConfig",
107+
"RecursiveLoop",
108+
"SourceKMSKeyArn",
109+
"TenancyConfig",
110+
],
105111
}
106112

107113
def __init__(self, template: Dict[str, Any]) -> None:

samtranslator/schema/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278502,6 +278502,9 @@
278502278502
"title": "Tags",
278503278503
"type": "object"
278504278504
},
278505+
"TenancyConfig": {
278506+
"$ref": "#/definitions/PassThroughProp"
278507+
},
278505278508
"Timeout": {
278506278509
"allOf": [
278507278510
{
@@ -278899,6 +278902,9 @@
278899278902
"title": "Tags",
278900278903
"type": "object"
278901278904
},
278905+
"TenancyConfig": {
278906+
"$ref": "#/definitions/PassThroughProp"
278907+
},
278902278908
"Timeout": {
278903278909
"allOf": [
278904278910
{

0 commit comments

Comments
 (0)