@@ -27,7 +27,8 @@ class ApiGenerator(object):
2727 def __init__ (self , logical_id , cache_cluster_enabled , cache_cluster_size , variables , depends_on ,
2828 definition_body , definition_uri , name , stage_name , endpoint_configuration = None ,
2929 method_settings = None , binary_media = None , cors = None , auth = None , access_log_setting = None ,
30- canary_setting = None , tracing_enabled = None ):
30+ canary_setting = None , tracing_enabled = None , resource_attributes = None ,
31+ passthrough_resource_attributes = None ):
3132 """Constructs an API Generator class that generates API Gateway resources
3233
3334 :param logical_id: Logical id of the SAM API Resource
@@ -42,6 +43,8 @@ def __init__(self, logical_id, cache_cluster_enabled, cache_cluster_size, variab
4243 :param access_log_setting: Whether to send access logs and where for Stage
4344 :param canary_setting: Canary Setting for Stage
4445 :param tracing_enabled: Whether active tracing with X-ray is enabled
46+ :param resource_attributes: Resource attributes to add to API resources
47+ :param passthrough_resource_attributes: Attributes such as `Condition` that are added to derived resources
4548 """
4649 self .logical_id = logical_id
4750 self .cache_cluster_enabled = cache_cluster_enabled
@@ -60,14 +63,16 @@ def __init__(self, logical_id, cache_cluster_enabled, cache_cluster_size, variab
6063 self .access_log_setting = access_log_setting
6164 self .canary_setting = canary_setting
6265 self .tracing_enabled = tracing_enabled
66+ self .resource_attributes = resource_attributes
67+ self .passthrough_resource_attributes = passthrough_resource_attributes
6368
6469 def _construct_rest_api (self ):
6570 """Constructs and returns the ApiGateway RestApi.
6671
6772 :returns: the RestApi to which this SAM Api corresponds
6873 :rtype: model.apigateway.ApiGatewayRestApi
6974 """
70- rest_api = ApiGatewayRestApi (self .logical_id , depends_on = self .depends_on )
75+ rest_api = ApiGatewayRestApi (self .logical_id , depends_on = self .depends_on , attributes = self . resource_attributes )
7176 rest_api .BinaryMediaTypes = self .binary_media
7277
7378 if self .endpoint_configuration :
@@ -132,7 +137,8 @@ def _construct_deployment(self, rest_api):
132137 :returns: the Deployment to which this SAM Api corresponds
133138 :rtype: model.apigateway.ApiGatewayDeployment
134139 """
135- deployment = ApiGatewayDeployment (self .logical_id + 'Deployment' )
140+ deployment = ApiGatewayDeployment (self .logical_id + 'Deployment' ,
141+ attributes = self .passthrough_resource_attributes )
136142 deployment .RestApiId = rest_api .get_runtime_attr ('rest_api_id' )
137143 deployment .StageName = 'Stage'
138144
@@ -150,7 +156,8 @@ def _construct_stage(self, deployment, swagger):
150156 # This will NOT create duplicates because we allow only ONE stage per API resource
151157 stage_name_prefix = self .stage_name if isinstance (self .stage_name , string_types ) else ""
152158
153- stage = ApiGatewayStage (self .logical_id + stage_name_prefix + 'Stage' )
159+ stage = ApiGatewayStage (self .logical_id + stage_name_prefix + 'Stage' ,
160+ attributes = self .passthrough_resource_attributes )
154161 stage .RestApiId = ref (self .logical_id )
155162 stage .update_deployment_ref (deployment .logical_id )
156163 stage .StageName = self .stage_name
@@ -294,15 +301,16 @@ def _get_permission(self, authorizer_name, authorizer_lambda_function_arn):
294301 :returns: the permission resource
295302 :rtype: model.lambda_.LambdaPermission
296303 """
297- rest_api = ApiGatewayRestApi (self .logical_id , depends_on = self .depends_on )
304+ rest_api = ApiGatewayRestApi (self .logical_id , depends_on = self .depends_on , attributes = self . resource_attributes )
298305 api_id = rest_api .get_runtime_attr ('rest_api_id' )
299306
300307 partition = ArnGenerator .get_partition_name ()
301308 resource = '${__ApiId__}/authorizers/*'
302309 source_arn = fnSub (ArnGenerator .generate_arn (partition = partition , service = 'execute-api' , resource = resource ),
303310 {"__ApiId__" : api_id })
304311
305- lambda_permission = LambdaPermission (self .logical_id + authorizer_name + 'AuthorizerPermission' )
312+ lambda_permission = LambdaPermission (self .logical_id + authorizer_name + 'AuthorizerPermission' ,
313+ attributes = self .passthrough_resource_attributes )
306314 lambda_permission .Action = 'lambda:invokeFunction'
307315 lambda_permission .FunctionName = authorizer_lambda_function_arn
308316 lambda_permission .Principal = 'apigateway.amazonaws.com'
0 commit comments