diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index e2bd33876..c293b6ba6 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -1070,6 +1070,12 @@ def _add_openapi_integration(self, api, function, manage_swagger=False): self._add_auth_to_openapi_integration(api, editor) if self.TimeoutInMillis: editor.add_timeout_to_method(api=api, path=self.Path, method_name=self.Method, timeout=self.TimeoutInMillis) + path_parameters = re.findall("{(.*?)}", self.Path) + if path_parameters: + editor.add_path_parameters_to_method( + api=api, path=self.Path, method_name=self.Method, path_parameters=path_parameters + ) + api["DefinitionBody"] = editor.openapi def _add_auth_to_openapi_integration(self, api, editor): diff --git a/samtranslator/open_api/open_api.py b/samtranslator/open_api/open_api.py index 14ab3dcac..bcc13fc74 100644 --- a/samtranslator/open_api/open_api.py +++ b/samtranslator/open_api/open_api.py @@ -257,6 +257,38 @@ def add_timeout_to_method(self, api, path, method_name, timeout): if self.method_definition_has_integration(method_definition): method_definition[self._X_APIGW_INTEGRATION]["timeoutInMillis"] = timeout + def add_path_parameters_to_method(self, api, path, method_name, path_parameters): + """ + Adds path parameters to this path + method + + :param dict api: Reference to the related Api's properties as defined in the template. + :param string path: Path name + :param string method_name: Method name + :param list path_parameters: list of strings of path parameters + """ + normalized_method_name = self._normalize_method_name(method_name) + for method_definition in self.get_method_contents(self.get_path(path)[normalized_method_name]): + # create path parameter list + # add it here if it doesn't exist, merge with existing otherwise. + method_definition.setdefault("parameters", []) + for param in path_parameters: + # find an existing parameter with this name if it exists + existing_parameter = next( + ( + existing_parameter + for existing_parameter in method_definition.get("parameters", []) + if existing_parameter.get("name") == param + ), + None, + ) + if existing_parameter: + # overwrite parameter values for existing path parameter + existing_parameter["in"] = "path" + existing_parameter["required"] = True + else: + parameter = {"name": param, "in": "path", "required": True} + method_definition.get("parameters").append(parameter) + def add_authorizers_security_definitions(self, authorizers): """ Add Authorizer definitions to the securityDefinitions part of Swagger. diff --git a/tests/translator/input/http_api_existing_openapi.yaml b/tests/translator/input/http_api_existing_openapi.yaml index 79efad616..75ec016ea 100644 --- a/tests/translator/input/http_api_existing_openapi.yaml +++ b/tests/translator/input/http_api_existing_openapi.yaml @@ -35,6 +35,12 @@ Resources: Properties: ApiId: !Ref MyApi TimeoutInMillis: !Ref Timeout + PathParametersExisting: + Type: HttpApi + Properties: + ApiId: !Ref MyApi + Path: /get/{something}/with/{params} + Method: GET MyApi: Type: AWS::Serverless::HttpApi Properties: @@ -65,6 +71,13 @@ Resources: - OpenIdAuth: - scope3 responses: {} + "/get/{something}/with/{params}": + get: + parameters: + - + name: something + in: path + responses: {} "/integration": post: x-amazon-apigateway-integration: diff --git a/tests/translator/input/implicit_http_api.yaml b/tests/translator/input/implicit_http_api.yaml index 536e3f266..ee141d7d5 100644 --- a/tests/translator/input/implicit_http_api.yaml +++ b/tests/translator/input/implicit_http_api.yaml @@ -28,3 +28,8 @@ Resources: Properties: Path: /basic2 Method: post + PathParameters: + Type: HttpApi + Properties: + Path: /get/{something}/with/{params} + Method: POST diff --git a/tests/translator/output/aws-cn/http_api_existing_openapi.json b/tests/translator/output/aws-cn/http_api_existing_openapi.json index c1df5c259..0d81ea2b9 100644 --- a/tests/translator/output/aws-cn/http_api_existing_openapi.json +++ b/tests/translator/output/aws-cn/http_api_existing_openapi.json @@ -105,6 +105,31 @@ } }, "paths": { + "/get/{something}/with/{params}": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + }, + "payloadFormatVersion": "1.0" + }, + "responses": {}, + "parameters": [ + { + "required": true, + "name": "something", + "in": "path" + }, + { + "required": true, + "name": "params", + "in": "path" + } + ] + } + }, "/basic": { "post": { "x-amazon-apigateway-integration": { diff --git a/tests/translator/output/aws-cn/implicit_http_api.json b/tests/translator/output/aws-cn/implicit_http_api.json index 1769e0cd4..e0ea540b3 100644 --- a/tests/translator/output/aws-cn/implicit_http_api.json +++ b/tests/translator/output/aws-cn/implicit_http_api.json @@ -16,10 +16,6 @@ "HttpApiFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -36,6 +32,10 @@ } ] }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { "Value": "SAM", @@ -47,10 +47,6 @@ "HttpApiFunction2Role": { "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -67,6 +63,77 @@ } ] }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "HttpApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.restapi", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "HttpApiFunctionSimpleCasePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessHttpApi" + } + } + ] + } + } + }, + "HttpApiFunction2": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.restapi", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Role": { + "Fn::GetAtt": [ + "HttpApiFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { "Value": "SAM", @@ -85,12 +152,6 @@ "Ref": "AWS::StackName" } }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], "paths": { "/basic2": { "post": { @@ -105,17 +166,29 @@ "responses": {} } }, - "/basic": { + "/get/{something}/with/{params}": { "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" }, "payloadFormatVersion": "1.0" }, - "responses": {} + "responses": {}, + "parameters": [ + { + "required": true, + "name": "something", + "in": "path" + }, + { + "required": true, + "name": "params", + "in": "path" + } + ] } }, "$default": { @@ -131,23 +204,42 @@ "isDefaultRoute": true, "responses": {} } + }, + "/basic": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + }, + "payloadFormatVersion": "1.0" + }, + "responses": {} + } } }, - "openapi": "3.0.1" + "openapi": "3.0.1", + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] } } }, - "HttpApiFunctionSimpleCasePermission": { + "HttpApiFunction2PathParametersPermission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "HttpApiFunction" + "Ref": "HttpApiFunction2" }, "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", { "__Stage__": "*", "__ApiId__": { @@ -158,52 +250,6 @@ } } }, - "HttpApiFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, "HttpApiFunction2Basic2Permission": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -226,4 +272,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/http_api_existing_openapi.json b/tests/translator/output/aws-us-gov/http_api_existing_openapi.json index 01da21adf..a00a253b7 100644 --- a/tests/translator/output/aws-us-gov/http_api_existing_openapi.json +++ b/tests/translator/output/aws-us-gov/http_api_existing_openapi.json @@ -105,6 +105,31 @@ } }, "paths": { + "/get/{something}/with/{params}": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + }, + "payloadFormatVersion": "1.0" + }, + "responses": {}, + "parameters": [ + { + "required": true, + "name": "something", + "in": "path" + }, + { + "required": true, + "name": "params", + "in": "path" + } + ] + } + }, "/basic": { "post": { "x-amazon-apigateway-integration": { diff --git a/tests/translator/output/aws-us-gov/implicit_http_api.json b/tests/translator/output/aws-us-gov/implicit_http_api.json index 46660faf3..9237946d9 100644 --- a/tests/translator/output/aws-us-gov/implicit_http_api.json +++ b/tests/translator/output/aws-us-gov/implicit_http_api.json @@ -16,10 +16,6 @@ "HttpApiFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -36,6 +32,10 @@ } ] }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { "Value": "SAM", @@ -47,10 +47,6 @@ "HttpApiFunction2Role": { "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -67,6 +63,77 @@ } ] }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "HttpApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.restapi", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "HttpApiFunctionSimpleCasePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessHttpApi" + } + } + ] + } + } + }, + "HttpApiFunction2": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.restapi", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Role": { + "Fn::GetAtt": [ + "HttpApiFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { "Value": "SAM", @@ -85,12 +152,6 @@ "Ref": "AWS::StackName" } }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], "paths": { "/basic2": { "post": { @@ -105,17 +166,29 @@ "responses": {} } }, - "/basic": { + "/get/{something}/with/{params}": { "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" }, "payloadFormatVersion": "1.0" }, - "responses": {} + "responses": {}, + "parameters": [ + { + "required": true, + "name": "something", + "in": "path" + }, + { + "required": true, + "name": "params", + "in": "path" + } + ] } }, "$default": { @@ -131,23 +204,42 @@ "isDefaultRoute": true, "responses": {} } + }, + "/basic": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + }, + "payloadFormatVersion": "1.0" + }, + "responses": {} + } } }, - "openapi": "3.0.1" + "openapi": "3.0.1", + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] } } }, - "HttpApiFunctionSimpleCasePermission": { + "HttpApiFunction2PathParametersPermission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "HttpApiFunction" + "Ref": "HttpApiFunction2" }, "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", { "__Stage__": "*", "__ApiId__": { @@ -158,52 +250,6 @@ } } }, - "HttpApiFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, "HttpApiFunction2Basic2Permission": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -226,4 +272,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/translator/output/http_api_existing_openapi.json b/tests/translator/output/http_api_existing_openapi.json index 8edcb35ab..649327253 100644 --- a/tests/translator/output/http_api_existing_openapi.json +++ b/tests/translator/output/http_api_existing_openapi.json @@ -105,6 +105,31 @@ } }, "paths": { + "/get/{something}/with/{params}": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + }, + "payloadFormatVersion": "1.0" + }, + "responses": {}, + "parameters": [ + { + "required": true, + "name": "something", + "in": "path" + }, + { + "required": true, + "name": "params", + "in": "path" + } + ] + } + }, "/basic": { "post": { "x-amazon-apigateway-integration": { diff --git a/tests/translator/output/implicit_http_api.json b/tests/translator/output/implicit_http_api.json index 31bab6799..edd87913e 100644 --- a/tests/translator/output/implicit_http_api.json +++ b/tests/translator/output/implicit_http_api.json @@ -16,10 +16,6 @@ "HttpApiFunctionRole": { "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -36,6 +32,10 @@ } ] }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { "Value": "SAM", @@ -47,10 +47,6 @@ "HttpApiFunction2Role": { "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ @@ -67,6 +63,77 @@ } ] }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "HttpApiFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.restapi", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "HttpApiFunctionSimpleCasePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "ServerlessHttpApi" + } + } + ] + } + } + }, + "HttpApiFunction2": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.restapi", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Role": { + "Fn::GetAtt": [ + "HttpApiFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { "Value": "SAM", @@ -85,12 +152,6 @@ "Ref": "AWS::StackName" } }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], "paths": { "/basic2": { "post": { @@ -105,17 +166,29 @@ "responses": {} } }, - "/basic": { + "/get/{something}/with/{params}": { "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" }, "payloadFormatVersion": "1.0" }, - "responses": {} + "responses": {}, + "parameters": [ + { + "required": true, + "name": "something", + "in": "path" + }, + { + "required": true, + "name": "params", + "in": "path" + } + ] } }, "$default": { @@ -131,23 +204,42 @@ "isDefaultRoute": true, "responses": {} } + }, + "/basic": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + }, + "payloadFormatVersion": "1.0" + }, + "responses": {} + } } }, - "openapi": "3.0.1" + "openapi": "3.0.1", + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] } } }, - "HttpApiFunctionSimpleCasePermission": { + "HttpApiFunction2PathParametersPermission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "HttpApiFunction" + "Ref": "HttpApiFunction2" }, "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", { "__Stage__": "*", "__ApiId__": { @@ -158,52 +250,6 @@ } } }, - "HttpApiFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, "HttpApiFunction2Basic2Permission": { "Type": "AWS::Lambda::Permission", "Properties": { @@ -226,4 +272,4 @@ } } } -} +} \ No newline at end of file