diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 1bad8d41c..4933aeeb6 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -805,7 +805,7 @@ def _create_basepath_mapping( basepath_mapping.DomainName = ref(api_domain_name) basepath_mapping.RestApiId = ref(rest_api.logical_id) basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage") - if basepath: + if basepath is not None: basepath_mapping.BasePath = basepath return basepath_mapping diff --git a/tests/translator/input/api_with_custom_domains_edge_basePath.yaml b/tests/translator/input/api_with_custom_domains_edge_basePath.yaml new file mode 100644 index 000000000..e6157a926 --- /dev/null +++ b/tests/translator/input/api_with_custom_domains_edge_basePath.yaml @@ -0,0 +1,51 @@ +Parameters: + MyEdgeDomainName: + Type: String + MyEdgeDomainCert: + Type: String + HostedZoneId: + Type: String + +Resources: + MyFunction: + Type: AWS::Serverless::Function + Properties: + InlineCode: | + exports.handler = async (event) => { + const response = { + statusCode: 200, + body: JSON.stringify('Hello from Lambda!'), + }; + return response; + }; + Handler: index.handler + Runtime: nodejs18.x + Events: + Fetch: + Type: Api + Properties: + RestApiId: + Ref: MyApi + Method: Get + Path: /get + + MyApi: + Type: AWS::Serverless::Api + Properties: + OpenApiVersion: 3.0.1 + StageName: Prod + Domain: + DomainName: + Ref: MyEdgeDomainName + CertificateArn: + Ref: MyEdgeDomainCert + EndpointConfiguration: EDGE + BasePath: + - / + - /get + Route53: + HostedZoneId: + Ref: HostedZoneId + IpV6: true +Metadata: + SamTransformTest: true diff --git a/tests/translator/input/api_with_custom_domains_private_basePath.yaml b/tests/translator/input/api_with_custom_domains_private_basePath.yaml new file mode 100644 index 000000000..9c91ea318 --- /dev/null +++ b/tests/translator/input/api_with_custom_domains_private_basePath.yaml @@ -0,0 +1,65 @@ +Parameters: + DomainName: + Type: String + Default: private.example.com + Description: Custom domain name for the API + + CertificateArn: + Type: String + Default: another-api-arn + Description: ARN of the ACM certificate for the domain + + VpcEndpointId: + Type: String + Default: vpce-abcd1234efg + Description: VPC Endpoint ID for private API access + +Resources: + MyApi: + Type: AWS::Serverless::Api + Properties: + StageName: prod + Domain: + DomainName: !Ref DomainName + CertificateArn: !Ref CertificateArn + EndpointConfiguration: PRIVATE + BasePath: + - / + - /post + Policy: + Version: '2012-10-17' + Statement: + - Effect: Allow + Principal: '*' + Action: execute-api:Invoke + Resource: execute-api:/* + - Effect: Deny + Principal: '*' + Action: execute-api:Invoke + Resource: execute-api:/* + Condition: + StringNotEquals: + aws:SourceVpce: !Ref VpcEndpointId + Auth: + ResourcePolicy: + CustomStatements: + - Effect: Allow + Principal: '*' + Action: execute-api:Invoke + Resource: execute-api:/* + - Effect: Deny + Principal: '*' + Action: execute-api:Invoke + Resource: execute-api:/* + Condition: + StringNotEquals: + aws:SourceVpce: !Ref VpcEndpointId + +Outputs: + ApiDomainName: + Description: Custom Domain Name for the API + Value: !Ref MyApi.DomainNameV2 + + ApiEndpoint: + Description: API Gateway endpoint URL + Value: !Sub https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/ diff --git a/tests/translator/input/api_with_custom_domains_regional_basePath.yaml b/tests/translator/input/api_with_custom_domains_regional_basePath.yaml new file mode 100644 index 000000000..c0dcde2fa --- /dev/null +++ b/tests/translator/input/api_with_custom_domains_regional_basePath.yaml @@ -0,0 +1,54 @@ +Parameters: + MyRestRegionalDomainName: + Type: String + MyRestRegionalDomainCert: + Type: String + HostedZoneId: + Type: String + +Globals: + Api: + Domain: + DomainName: + Ref: MyRestRegionalDomainName + CertificateArn: + Ref: MyRestRegionalDomainCert + EndpointConfiguration: REGIONAL + MutualTlsAuthentication: + TruststoreUri: ${mtlsuri} + TruststoreVersion: 0 + SecurityPolicy: TLS_1_2 + BasePath: + - / + - /post + Route53: + HostedZoneId: + Ref: HostedZoneId + +Resources: + MyFunction: + Type: AWS::Serverless::Function + Properties: + InlineCode: | + exports.handler = async (event) => { + const response = { + statusCode: 200, + body: JSON.stringify('Hello from Lambda!'), + }; + return response; + }; + Handler: index.handler + Runtime: nodejs18.x + Events: + ImplicitGet: + Type: Api + Properties: + Method: Get + Path: /get + ImplicitPost: + Type: Api + Properties: + Method: Post + Path: /post +Metadata: + SamTransformTest: true diff --git a/tests/translator/output/api_with_custom_domains_edge_basePath.json b/tests/translator/output/api_with_custom_domains_edge_basePath.json new file mode 100644 index 000000000..c0cd368b0 --- /dev/null +++ b/tests/translator/output/api_with_custom_domains_edge_basePath.json @@ -0,0 +1,226 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Parameters": { + "HostedZoneId": { + "Type": "String" + }, + "MyEdgeDomainCert": { + "Type": "String" + }, + "MyEdgeDomainName": { + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainName9005ff2ee8": { + "Properties": { + "CertificateArn": { + "Ref": "MyEdgeDomainCert" + }, + "DomainName": { + "Ref": "MyEdgeDomainName" + }, + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/get": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainName": { + "Ref": "ApiGatewayDomainName9005ff2ee8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApiDeployment7c29f58b40": { + "Properties": { + "Description": "RestApi deployment id: 7c29f58b40342f987892da77b810a46514addb47", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment7c29f58b40" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApigetBasePathMapping": { + "Properties": { + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainName9005ff2ee8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup1194dea82a": { + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName9005ff2ee8", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": { + "Ref": "MyEdgeDomainName" + }, + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName9005ff2ee8", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": { + "Ref": "MyEdgeDomainName" + }, + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + } + } +} diff --git a/tests/translator/output/api_with_custom_domains_private_basePath.json b/tests/translator/output/api_with_custom_domains_private_basePath.json new file mode 100644 index 000000000..2c5ac9eb1 --- /dev/null +++ b/tests/translator/output/api_with_custom_domains_private_basePath.json @@ -0,0 +1,158 @@ +{ + "Outputs": { + "ApiDomainName": { + "Description": "Custom Domain Name for the API", + "Value": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + } + }, + "ApiEndpoint": { + "Description": "API Gateway endpoint URL", + "Value": { + "Fn::Sub": "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/" + } + } + }, + "Parameters": { + "CertificateArn": { + "Default": "another-api-arn", + "Description": "ARN of the ACM certificate for the domain", + "Type": "String" + }, + "DomainName": { + "Default": "private.example.com", + "Description": "Custom domain name for the API", + "Type": "String" + }, + "VpcEndpointId": { + "Default": "vpce-abcd1234efg", + "Description": "VPC Endpoint ID for private API access", + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainNameV27c603ed871": { + "Properties": { + "CertificateArn": "another-api-arn", + "DomainName": "private.example.com", + "EndpointConfiguration": { + "Types": [ + "PRIVATE" + ] + }, + "Policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": "execute-api:/*" + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "StringNotEquals": { + "aws:SourceVpce": "vpce-abcd1234efg" + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": "execute-api:/*" + } + ], + "Version": "2012-10-17" + } + }, + "Type": "AWS::ApiGateway::DomainNameV2" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": "execute-api:/*" + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "StringNotEquals": { + "aws:SourceVpce": "vpce-abcd1234efg" + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": "execute-api:/*" + } + ], + "Version": "2012-10-17" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainNameArn": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiprodStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMappingV2" + }, + "MyApiDeploymente37f6c9943": { + "Properties": { + "Description": "RestApi deployment id: e37f6c9943b5e1213efecf302864c9e775fcf695", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApipostBasePathMapping": { + "Properties": { + "BasePath": "post", + "DomainNameArn": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiprodStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMappingV2" + }, + "MyApiprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymente37f6c9943" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "prod" + }, + "Type": "AWS::ApiGateway::Stage" + } + } +} diff --git a/tests/translator/output/api_with_custom_domains_regional_basePath.json b/tests/translator/output/api_with_custom_domains_regional_basePath.json new file mode 100644 index 000000000..79117ae60 --- /dev/null +++ b/tests/translator/output/api_with_custom_domains_regional_basePath.json @@ -0,0 +1,254 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Parameters": { + "HostedZoneId": { + "Type": "String" + }, + "MyRestRegionalDomainCert": { + "Type": "String" + }, + "MyRestRegionalDomainName": { + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainName1a01391c0c": { + "Properties": { + "DomainName": { + "Ref": "MyRestRegionalDomainName" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "MutualTlsAuthentication": { + "TruststoreUri": "${mtlsuri}" + }, + "RegionalCertificateArn": { + "Ref": "MyRestRegionalDomainCert" + }, + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionImplicitGetPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitPostPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/post", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup1194dea82a": { + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName1a01391c0c", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName1a01391c0c", + "RegionalHostedZoneId" + ] + } + }, + "Name": { + "Ref": "MyRestRegionalDomainName" + }, + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/get": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + }, + "/post": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainName": { + "Ref": "ApiGatewayDomainName1a01391c0c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ServerlessRestApiDeploymentdfd08ecd45": { + "Properties": { + "Description": "RestApi deployment id: dfd08ecd455af89776b262d0c48a317e3252014d", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentdfd08ecd45" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ServerlessRestApipostBasePathMapping": { + "Properties": { + "BasePath": "post", + "DomainName": { + "Ref": "ApiGatewayDomainName1a01391c0c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + } + } +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domains_edge_basePath.json b/tests/translator/output/aws-cn/api_with_custom_domains_edge_basePath.json new file mode 100644 index 000000000..84b29d41b --- /dev/null +++ b/tests/translator/output/aws-cn/api_with_custom_domains_edge_basePath.json @@ -0,0 +1,234 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Parameters": { + "HostedZoneId": { + "Type": "String" + }, + "MyEdgeDomainCert": { + "Type": "String" + }, + "MyEdgeDomainName": { + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainName9005ff2ee8": { + "Properties": { + "CertificateArn": { + "Ref": "MyEdgeDomainCert" + }, + "DomainName": { + "Ref": "MyEdgeDomainName" + }, + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/get": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainName": { + "Ref": "ApiGatewayDomainName9005ff2ee8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApiDeploymentcd8cd4a8da": { + "Properties": { + "Description": "RestApi deployment id: cd8cd4a8daa0af4a1de3c8a035257bd64a5d1d11", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentcd8cd4a8da" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApigetBasePathMapping": { + "Properties": { + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainName9005ff2ee8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup1194dea82a": { + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName9005ff2ee8", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": { + "Ref": "MyEdgeDomainName" + }, + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName9005ff2ee8", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": { + "Ref": "MyEdgeDomainName" + }, + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + } + } +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domains_private_basePath.json b/tests/translator/output/aws-cn/api_with_custom_domains_private_basePath.json new file mode 100644 index 000000000..befafd072 --- /dev/null +++ b/tests/translator/output/aws-cn/api_with_custom_domains_private_basePath.json @@ -0,0 +1,166 @@ +{ + "Outputs": { + "ApiDomainName": { + "Description": "Custom Domain Name for the API", + "Value": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + } + }, + "ApiEndpoint": { + "Description": "API Gateway endpoint URL", + "Value": { + "Fn::Sub": "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/" + } + } + }, + "Parameters": { + "CertificateArn": { + "Default": "another-api-arn", + "Description": "ARN of the ACM certificate for the domain", + "Type": "String" + }, + "DomainName": { + "Default": "private.example.com", + "Description": "Custom domain name for the API", + "Type": "String" + }, + "VpcEndpointId": { + "Default": "vpce-abcd1234efg", + "Description": "VPC Endpoint ID for private API access", + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainNameV27c603ed871": { + "Properties": { + "CertificateArn": "another-api-arn", + "DomainName": "private.example.com", + "EndpointConfiguration": { + "Types": [ + "PRIVATE" + ] + }, + "Policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": "execute-api:/*" + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "StringNotEquals": { + "aws:SourceVpce": "vpce-abcd1234efg" + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": "execute-api:/*" + } + ], + "Version": "2012-10-17" + } + }, + "Type": "AWS::ApiGateway::DomainNameV2" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": "execute-api:/*" + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "StringNotEquals": { + "aws:SourceVpce": "vpce-abcd1234efg" + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": "execute-api:/*" + } + ], + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainNameArn": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiprodStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMappingV2" + }, + "MyApiDeploymente37f6c9943": { + "Properties": { + "Description": "RestApi deployment id: e37f6c9943b5e1213efecf302864c9e775fcf695", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApipostBasePathMapping": { + "Properties": { + "BasePath": "post", + "DomainNameArn": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiprodStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMappingV2" + }, + "MyApiprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymente37f6c9943" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "prod" + }, + "Type": "AWS::ApiGateway::Stage" + } + } +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domains_regional_basePath.json b/tests/translator/output/aws-cn/api_with_custom_domains_regional_basePath.json new file mode 100644 index 000000000..acb6638bc --- /dev/null +++ b/tests/translator/output/aws-cn/api_with_custom_domains_regional_basePath.json @@ -0,0 +1,262 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Parameters": { + "HostedZoneId": { + "Type": "String" + }, + "MyRestRegionalDomainCert": { + "Type": "String" + }, + "MyRestRegionalDomainName": { + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainName1a01391c0c": { + "Properties": { + "DomainName": { + "Ref": "MyRestRegionalDomainName" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "MutualTlsAuthentication": { + "TruststoreUri": "${mtlsuri}" + }, + "RegionalCertificateArn": { + "Ref": "MyRestRegionalDomainCert" + }, + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionImplicitGetPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitPostPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/post", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup1194dea82a": { + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName1a01391c0c", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName1a01391c0c", + "RegionalHostedZoneId" + ] + } + }, + "Name": { + "Ref": "MyRestRegionalDomainName" + }, + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/get": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + }, + "/post": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainName": { + "Ref": "ApiGatewayDomainName1a01391c0c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ServerlessRestApiDeployment8797cbd624": { + "Properties": { + "Description": "RestApi deployment id: 8797cbd624ca215824f9f365041a5ae8f9c49eae", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment8797cbd624" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ServerlessRestApipostBasePathMapping": { + "Properties": { + "BasePath": "post", + "DomainName": { + "Ref": "ApiGatewayDomainName1a01391c0c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + } + } +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domains_edge_basePath.json b/tests/translator/output/aws-us-gov/api_with_custom_domains_edge_basePath.json new file mode 100644 index 000000000..0532e7f2e --- /dev/null +++ b/tests/translator/output/aws-us-gov/api_with_custom_domains_edge_basePath.json @@ -0,0 +1,234 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Parameters": { + "HostedZoneId": { + "Type": "String" + }, + "MyEdgeDomainCert": { + "Type": "String" + }, + "MyEdgeDomainName": { + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainName9005ff2ee8": { + "Properties": { + "CertificateArn": { + "Ref": "MyEdgeDomainCert" + }, + "DomainName": { + "Ref": "MyEdgeDomainName" + }, + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/get": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainName": { + "Ref": "ApiGatewayDomainName9005ff2ee8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApiDeploymentf9a7aee6d1": { + "Properties": { + "Description": "RestApi deployment id: f9a7aee6d12f55ef7501475df6f08c671b0e5218", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentf9a7aee6d1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApigetBasePathMapping": { + "Properties": { + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainName9005ff2ee8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup1194dea82a": { + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName9005ff2ee8", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": { + "Ref": "MyEdgeDomainName" + }, + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName9005ff2ee8", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": { + "Ref": "MyEdgeDomainName" + }, + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + } + } +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domains_private_basePath.json b/tests/translator/output/aws-us-gov/api_with_custom_domains_private_basePath.json new file mode 100644 index 000000000..befafd072 --- /dev/null +++ b/tests/translator/output/aws-us-gov/api_with_custom_domains_private_basePath.json @@ -0,0 +1,166 @@ +{ + "Outputs": { + "ApiDomainName": { + "Description": "Custom Domain Name for the API", + "Value": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + } + }, + "ApiEndpoint": { + "Description": "API Gateway endpoint URL", + "Value": { + "Fn::Sub": "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/" + } + } + }, + "Parameters": { + "CertificateArn": { + "Default": "another-api-arn", + "Description": "ARN of the ACM certificate for the domain", + "Type": "String" + }, + "DomainName": { + "Default": "private.example.com", + "Description": "Custom domain name for the API", + "Type": "String" + }, + "VpcEndpointId": { + "Default": "vpce-abcd1234efg", + "Description": "VPC Endpoint ID for private API access", + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainNameV27c603ed871": { + "Properties": { + "CertificateArn": "another-api-arn", + "DomainName": "private.example.com", + "EndpointConfiguration": { + "Types": [ + "PRIVATE" + ] + }, + "Policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": "execute-api:/*" + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "StringNotEquals": { + "aws:SourceVpce": "vpce-abcd1234efg" + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": "execute-api:/*" + } + ], + "Version": "2012-10-17" + } + }, + "Type": "AWS::ApiGateway::DomainNameV2" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": "execute-api:/*" + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "StringNotEquals": { + "aws:SourceVpce": "vpce-abcd1234efg" + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": "execute-api:/*" + } + ], + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainNameArn": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiprodStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMappingV2" + }, + "MyApiDeploymente37f6c9943": { + "Properties": { + "Description": "RestApi deployment id: e37f6c9943b5e1213efecf302864c9e775fcf695", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApipostBasePathMapping": { + "Properties": { + "BasePath": "post", + "DomainNameArn": { + "Ref": "ApiGatewayDomainNameV27c603ed871" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiprodStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMappingV2" + }, + "MyApiprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymente37f6c9943" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "prod" + }, + "Type": "AWS::ApiGateway::Stage" + } + } +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domains_regional_basePath.json b/tests/translator/output/aws-us-gov/api_with_custom_domains_regional_basePath.json new file mode 100644 index 000000000..bcaa5fbef --- /dev/null +++ b/tests/translator/output/aws-us-gov/api_with_custom_domains_regional_basePath.json @@ -0,0 +1,262 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Parameters": { + "HostedZoneId": { + "Type": "String" + }, + "MyRestRegionalDomainCert": { + "Type": "String" + }, + "MyRestRegionalDomainName": { + "Type": "String" + } + }, + "Resources": { + "ApiGatewayDomainName1a01391c0c": { + "Properties": { + "DomainName": { + "Ref": "MyRestRegionalDomainName" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "MutualTlsAuthentication": { + "TruststoreUri": "${mtlsuri}" + }, + "RegionalCertificateArn": { + "Ref": "MyRestRegionalDomainCert" + }, + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionImplicitGetPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitPostPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/post", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup1194dea82a": { + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName1a01391c0c", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName1a01391c0c", + "RegionalHostedZoneId" + ] + } + }, + "Name": { + "Ref": "MyRestRegionalDomainName" + }, + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/get": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + }, + "/post": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiBasePathMapping": { + "Properties": { + "BasePath": "", + "DomainName": { + "Ref": "ApiGatewayDomainName1a01391c0c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ServerlessRestApiDeployment62123287c5": { + "Properties": { + "Description": "RestApi deployment id: 62123287c568397bf0c56295abac199a5de47607", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62123287c5" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ServerlessRestApipostBasePathMapping": { + "Properties": { + "BasePath": "post", + "DomainName": { + "Ref": "ApiGatewayDomainName1a01391c0c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + } + } +}