From 7d0c87ff8f8322b139549eb1e01b65f1db086d24 Mon Sep 17 00:00:00 2001 From: "Michael Barney, Jr" Date: Wed, 22 Jan 2020 16:28:04 -0500 Subject: [PATCH 1/7] Adds support for HostedZoneName instead of HostedZoneId in Domain section of Api --- samtranslator/model/api/api_generator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 5aedec4d19..827b2fae8d 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -338,7 +338,7 @@ def _construct_api_domain(self, rest_api): record_set_group = None if self.domain.get("Route53") is not None: route53 = self.domain.get("Route53") - if route53.get("HostedZoneId") is None: + if route53.get("HostedZoneId") is None and route53.get("HostedZoneName") is None: raise InvalidResourceException( self.logical_id, "HostedZoneId is required to enable Route53 support on Custom Domains." ) @@ -346,7 +346,10 @@ def _construct_api_domain(self, rest_api): record_set_group = Route53RecordSetGroup( "RecordSetGroup" + logical_id, attributes=self.passthrough_resource_attributes ) - record_set_group.HostedZoneId = route53.get("HostedZoneId") + if "HostedZoneId" in route53: + record_set_group.HostedZoneId = route53.get("HostedZoneId") + if "HostedZoneName" in route53: + record_set_group.HostedZoneName = route53.get("HostedZoneName") record_set_group.RecordSets = self._construct_record_sets_for_domain(self.domain) return domain, basepath_resource_list, record_set_group From f7298dd1ff21d27b159126e1602d8a1ffa7b77da Mon Sep 17 00:00:00 2001 From: "Michael Barney, Jr" Date: Wed, 22 Jan 2020 16:43:22 -0500 Subject: [PATCH 2/7] Updates documentation, adds example for hosted zone name support --- .../README.md | 22 ++++++ .../template.yaml | 71 +++++++++++++++++++ versions/2016-10-31.md | 55 +++++++------- 3 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/README.md create mode 100644 examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/template.yaml diff --git a/examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/README.md b/examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/README.md new file mode 100644 index 0000000000..6b66c0ea7a --- /dev/null +++ b/examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/README.md @@ -0,0 +1,22 @@ +# Custom Domains support + +Example SAM template for setting up Api Gateway resources for custom domains. + +## Prerequisites for setting up custom domains +1. A domain name. You can purchase a domain name from a domain name provider. +1. A certificate ARN. Set up or import a valid certificate into AWS Certificate Manager. If the endpoint is EDGE, the certificate must be created in us-east-1. +1. A HostedZone in Route53 for the domain name. + +## PostRequisites +After deploying the template, make sure you configure the DNS settings on the domain name provider's website. You will need to add Type A and Type AAAA DNS records that are point to ApiGateway's Hosted Zone Id. Read more [here](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html) + +## Running the example + +```bash +$ sam deploy \ + --template-file /path_to_template/packaged-template.yaml \ + --stack-name my-new-stack \ + --capabilities CAPABILITY_IAM +``` + +Curl to the endpoint "http://example.com/home/fetch" should hit the Api. \ No newline at end of file diff --git a/examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/template.yaml b/examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/template.yaml new file mode 100644 index 0000000000..144d8619e8 --- /dev/null +++ b/examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/template.yaml @@ -0,0 +1,71 @@ +Parameters: + DomainName: + Type: String + Default: 'example.com' + ACMCertificateArn: + Type: String + Default: 'cert-arn-in-us-east-1' +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: nodejs8.10 + Events: + Fetch: + Type: Api + Properties: + RestApiId: !Ref MyApi + Method: Post + Path: /fetch + + MyApi: + Type: AWS::Serverless::Api + Properties: + OpenApiVersion: 3.0.1 + StageName: Prod + Domain: + DomainName: !Ref DomainName + CertificateArn: !Ref ACMCertificateArn + EndpointConfiguration: EDGE + BasePath: + - /home + Route53: + HostedZoneName: www.my-domain.com. + IpV6: true +## ====== Everything below here is optional, leave this out if you want to use the internal Api Gateway distribution ======= + DistributionDomainName: !GetAtt Distribution.DomainName + + Distribution: + Type: AWS::CloudFront::Distribution + Properties: + DistributionConfig: + Enabled: true + HttpVersion: http2 + Origins: + - DomainName: !Ref DomainName + Id: !Ref DomainName + CustomOriginConfig: + HTTPPort: 80 + HTTPSPort: 443 + OriginProtocolPolicy: https-only + DefaultCacheBehavior: + AllowedMethods: [ HEAD, DELETE, POST, GET, OPTIONS, PUT, PATCH ] + ForwardedValues: + QueryString: false + SmoothStreaming: false + Compress: true + TargetOriginId: !Ref DomainName + ViewerProtocolPolicy: redirect-to-https + PriceClass: PriceClass_100 + ViewerCertificate: + SslSupportMethod: sni-only + AcmCertificateArn: !Ref ACMCertificateArn \ No newline at end of file diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index a27af7642e..c3118e203e 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -16,7 +16,7 @@ The AWS Serverless Application Model (SAM) is licensed under [The Apache License * [Event source types](#event-source-types) * [Property types](#property-types) * [Data types](#data-types) - + ## Introduction NOTE: SAM specification documentation is in process of being migrated to official [AWS SAM docs](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) page, please take a look at the [SAM specification](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification.html) there. @@ -129,7 +129,7 @@ Tracing | `string` | String that specifies the function's [X-Ray tracing mode](h KmsKeyArn | `string` | The Amazon Resource Name (ARN) of an AWS Key Management Service (AWS KMS) key that Lambda uses to encrypt and decrypt your function's environment variables. DeadLetterQueue | `map` | [DeadLetterQueue Object](#deadletterqueue-object) | Configures SNS topic or SQS queue where Lambda sends events that it can't process. DeploymentPreference | [DeploymentPreference Object](#deploymentpreference-object) | Settings to enable Safe Lambda Deployments. Read the [usage guide](../docs/safe_lambda_deployments.rst) for detailed information. -Layers | list of `string` | List of LayerVersion ARNs that should be used by this function. The order specified here is the order that they will be imported when running the Lambda function. +Layers | list of `string` | List of LayerVersion ARNs that should be used by this function. The order specified here is the order that they will be imported when running the Lambda function. AutoPublishAlias | `string` | Name of the Alias. Read [AutoPublishAlias Guide](../docs/safe_lambda_deployments.rst#instant-traffic-shifting-using-lambda-aliases) for how it works VersionDescription | `string` | A string that specifies the Description field which will be added on the new lambda version ReservedConcurrentExecutions | `integer` | The maximum of concurrent executions you want to reserve for the function. For more information see [AWS Documentation on managing concurrency](https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html) @@ -156,7 +156,7 @@ When you use `AutoPublishAlias` property, SAM will generate a Lambda Version and Example: -Assume the following Serverless Function +Assume the following Serverless Function ```yaml Resources: @@ -349,7 +349,7 @@ Property Name | Type | Description ---|:---:|--- PrimaryKey | [Primary Key Object](#primary-key-object) | Attribute name and type to be used as the table's primary key. **This cannot be modified without replacing the resource.** Defaults to `String` attribute named `id`. ProvisionedThroughput | [Provisioned Throughput Object](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-provisionedthroughput.html) | Read and write throughput provisioning information. If ProvisionedThroughput is not specified BillingMode will be specified as PAY_PER_REQUEST -Tags | Map of `string` to `string` | A map (string to string) that specifies the tags to be added to this table. Keys and values are limited to alphanumeric characters. +Tags | Map of `string` to `string` | A map (string to string) that specifies the tags to be added to this table. Keys and values are limited to alphanumeric characters. TableName | `string` | Name for the DynamoDB Table SSESpecification | [DynamoDB SSESpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-ssespecification.html) | Specifies the settings to enable server-side encryption. @@ -474,10 +474,10 @@ Type: SNS Properties: Topic: arn:aws:sns:us-east-1:123456789012:my_topic FilterPolicy: - store: + store: - example_corp - price_usd: - - numeric: + price_usd: + - numeric: - ">=" - 100 ``` @@ -586,7 +586,7 @@ Properties: ``` #### Destination Config Object - + Expired record metatadata/retries exhausted metadata is sent to this destination after they have passed the defined limits. ##### Properties @@ -597,7 +597,7 @@ DestinationConfig | [OnFailure Object](#onfailure-object) | On failure all the m #### OnFailure Object Property Name | Type | Description ---|:---:|--- -Destination | `string` | Destination arn to redirect to either a SQS or a SNS resource +Destination | `string` | Destination arn to redirect to either a SQS or a SNS resource Type | `string` | This field accepts either `SQS` or `SNS` as input. This sets the required policies for sending or publishing messages to SQS or SNS resource on failure @@ -690,7 +690,7 @@ Properties: The object describing an event source with type `CloudWatchEvent`. -The CloudWatch Events service has been re-launched as Amazon EventBridge with full backwards compatibility. Please see the subsequent [EventBridgeRule](#eventbridgerule) section. +The CloudWatch Events service has been re-launched as Amazon EventBridge with full backwards compatibility. Please see the subsequent [EventBridgeRule](#eventbridgerule) section. ##### Properties @@ -859,7 +859,7 @@ ProvisionedConcurrentExecutions | `string` | Number of concurrent executions to #### Event Invoke Config object -The object describing event invoke config on a Lambda function. +The object describing event invoke config on a Lambda function. ```yaml MyFunction: @@ -872,7 +872,7 @@ The object describing event invoke config on a Lambda function. OnSuccess: Type: [SQS | SNS | EventBridge | Function] Destination: ARN of [SQS | SNS | EventBridge | Function] - OnFailure: + OnFailure: Type: [SQS | SNS | EventBridge | Function] Destination: ARN of [SQS | SNS | EventBridge | Function] ``` @@ -903,7 +903,7 @@ Type | `string` | Type of the Resource to be invoked. Values could be [SQS | SNS Destination | `string` | ARN of the resource to be invoked. Fn::If and Ref is supported on this property. The corresponding policies for the resource are generated in SAM. -Destination Property is required if Type is EventBridge and Lambda. If Type is SQS or SNS, and Destination is None, SAM auto creates these resources in the template. +Destination Property is required if Type is EventBridge and Lambda. If Type is SQS or SNS, and Destination is None, SAM auto creates these resources in the template. ##### Generated Resources Property Name | Type | Alias to Ref the Auto-Created Resource @@ -975,8 +975,8 @@ Syntax: ```yaml DeadLetterQueue: - Type: `SQS` or `SNS` - TargetArn: ARN of the SQS queue or SNS topic to use as DLQ. + Type: `SQS` or `SNS` + TargetArn: ARN of the SQS queue or SNS topic to use as DLQ. ``` #### DeploymentPreference Object @@ -996,7 +996,7 @@ DeploymentPreference: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction TriggerConfigurations: - # A list of trigger configurations you want to associate with the deployment group. Used to notify an SNS topic on + # A list of trigger configurations you want to associate with the deployment group. Used to notify an SNS topic on # lifecycle events. - TriggerEvents: # A list of events to trigger on. @@ -1011,17 +1011,17 @@ Enable and configure CORS for the APIs. Enabling CORS will allow your API to be ```yaml Cors: - AllowMethods: Optional. String containing the HTTP methods to allow. - # For example, "'GET,POST,DELETE'". If you omit this property, then SAM will automatically allow all the methods configured for each API. + AllowMethods: Optional. String containing the HTTP methods to allow. + # For example, "'GET,POST,DELETE'". If you omit this property, then SAM will automatically allow all the methods configured for each API. # Checkout [HTTP Spec](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods) more details on the value. - AllowHeaders: Optional. String of headers to allow. + AllowHeaders: Optional. String of headers to allow. # For example, "'X-Forwarded-For'". Checkout [HTTP Spec](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers) for more details on the value - AllowOrigin: Required. String of origin to allow. + AllowOrigin: Required. String of origin to allow. # For example, "'www.example.com'". Checkout [HTTP Spec](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin) for more details on this value. - MaxAge: Optional. String containing the number of seconds to cache CORS Preflight request. + MaxAge: Optional. String containing the number of seconds to cache CORS Preflight request. # For example, "'600'" will cache request for 600 seconds. Checkout [HTTP Spec](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age) for more details on this value AllowCredentials: Optional. Boolean indicating whether request is allowed to contain credentials. @@ -1032,7 +1032,7 @@ Cors: #### API Auth Object -Configure Auth on APIs. +Configure Auth on APIs. **Authorizers:** Define Lambda and Cognito `Authorizers` and specify a `DefaultAuthorizer`. If you use IAM permission, only specify `AWS_IAM` to a `DefaultAuthorizer`. For more information, see the documentation on [Lambda Authorizers](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html) and [Amazon Cognito User Pool Authorizers](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html) and [IAM Permissions](https://docs.aws.amazon.com/apigateway/latest/developerguide/permissions.html). @@ -1045,7 +1045,7 @@ Auth: DefaultAuthorizer: MyCognitoAuth # OPTIONAL, if you use IAM permissions, specify AWS_IAM. AddDefaultAuthorizerToCorsPreflight: false # OPTIONAL; Default: true ResourcePolicy: - CustomStatements: + CustomStatements: - Effect: Allow Principal: * Action: execute-api:Invoke @@ -1109,7 +1109,7 @@ Configure Resource Policy for all methods and paths on an API. This setting can ```yaml Auth: ResourcePolicy: - CustomStatements: + CustomStatements: - Effect: Allow Principal: * Action: execute-api:Invoke @@ -1224,9 +1224,10 @@ Domain: CertificateARN: String # REQUIRED | Must be a valid [certificate ARN](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-certificatemanager-certificate.html), and for EDGE endpoint configuration the certificate must be in us-east-1 EndpointConfiguration: "EDGE" # optional | Default value is REGIONAL | Accepted values are EDGE | REGIONAL BasePath: - - String # optional | Default value is '/' | List of basepaths to be configured with the ApiGateway Domain Name + - String # optional | Default value is '/' | List of basepaths to be configured with the ApiGateway Domain Name Route53: # optional | Default behavior is to treat as None - does not create Route53 resources | Enable these settings to create Route53 Recordsets - HostedZoneId: String # REQUIRED | Must be a hostedzoneid value of a [`AWS::Route53::HostedZone`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-route53-hostedzone.html) resource + HostedZoneId: String # ONE OF `HostedZoneId`, `HostedZoneName` REQUIRED | Must be a hostedzoneid value of a [`AWS::Route53::HostedZone`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-route53-hostedzone.html) resource + HostedZoneName: String # ONE OF `HostedZoneId`, `HostedZoneName` REQUIRED | Must be the `Name` of an [`AWS::Route53::HostedZone`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-route53-hostedzone.html) resource EvaluateTargetHealth: Boolean # optional | default value is false - DistributionDomainName: String # OPTIONAL if the EndpointConfiguration is EDGE | Default points to Api Gateway Distribution | Domain name of a [cloudfront distribution](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html) + DistributionDomainName: String # OPTIONAL if the EndpointConfiguration is EDGE | Default points to Api Gateway Distribution | Domain name of a [cloudfront distribution](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html) ``` From b18fe73353efe5e8c2600352fdb3582994c5d000 Mon Sep 17 00:00:00 2001 From: Michael Barney Jr Date: Wed, 22 Jan 2020 17:11:14 -0500 Subject: [PATCH 3/7] Update samtranslator/model/api/api_generator.py Co-Authored-By: Timo Schilling --- samtranslator/model/api/api_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 827b2fae8d..35947df28c 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -340,7 +340,7 @@ def _construct_api_domain(self, rest_api): route53 = self.domain.get("Route53") if route53.get("HostedZoneId") is None and route53.get("HostedZoneName") is None: raise InvalidResourceException( - self.logical_id, "HostedZoneId is required to enable Route53 support on Custom Domains." + self.logical_id, "HostedZoneId or HostedZoneName is required to enable Route53 support on Custom Domains." ) logical_id = logical_id_generator.LogicalIdGenerator("", route53.get("HostedZoneId")).gen() record_set_group = Route53RecordSetGroup( From 255284ecd2b9dc142f3e76108d26244d4aeb8565 Mon Sep 17 00:00:00 2001 From: "Michael Barney, Jr" Date: Wed, 22 Jan 2020 18:16:48 -0500 Subject: [PATCH 4/7] adds tests, fixes missing piece in logicalID generator --- samtranslator/model/api/api_generator.py | 2 +- samtranslator/model/route53.py | 6 +- ...ustom_domain_route53_hosted_zone_name.yaml | 43 ++++ ...ustom_domain_route53_hosted_zone_name.json | 197 +++++++++++++++++ ...ustom_domain_route53_hosted_zone_name.json | 205 ++++++++++++++++++ .../api_with_custom_domain_route53.json | 124 +++++------ ...ustom_domain_route53_hosted_zone_name.json | 205 ++++++++++++++++++ tests/translator/test_translator.py | 2 + 8 files changed, 720 insertions(+), 64 deletions(-) create mode 100644 tests/translator/input/api_with_custom_domain_route53_hosted_zone_name.yaml create mode 100644 tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json create mode 100644 tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json create mode 100644 tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 827b2fae8d..2e750c73dc 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -342,7 +342,7 @@ def _construct_api_domain(self, rest_api): raise InvalidResourceException( self.logical_id, "HostedZoneId is required to enable Route53 support on Custom Domains." ) - logical_id = logical_id_generator.LogicalIdGenerator("", route53.get("HostedZoneId")).gen() + logical_id = logical_id_generator.LogicalIdGenerator("", route53.get("HostedZoneId") or route53.get("HostedZoneName")).gen() record_set_group = Route53RecordSetGroup( "RecordSetGroup" + logical_id, attributes=self.passthrough_resource_attributes ) diff --git a/samtranslator/model/route53.py b/samtranslator/model/route53.py index dcb94818b7..3eb7ec4b74 100644 --- a/samtranslator/model/route53.py +++ b/samtranslator/model/route53.py @@ -4,4 +4,8 @@ class Route53RecordSetGroup(Resource): resource_type = "AWS::Route53::RecordSetGroup" - property_types = {"HostedZoneId": PropertyType(False, is_str()), "RecordSets": PropertyType(False, is_type(list))} + property_types = { + "HostedZoneId": PropertyType(False, is_str()), + "HostedZoneName": PropertyType(False, is_str()), + "RecordSets": PropertyType(False, is_type(list)), + } diff --git a/tests/translator/input/api_with_custom_domain_route53_hosted_zone_name.yaml b/tests/translator/input/api_with_custom_domain_route53_hosted_zone_name.yaml new file mode 100644 index 0000000000..36120739ba --- /dev/null +++ b/tests/translator/input/api_with_custom_domain_route53_hosted_zone_name.yaml @@ -0,0 +1,43 @@ +Parameters: + DomainName: + Type: String + Default: 'example.com' + ACMCertificateArn: + Type: String + Default: 'cert-arn-in-us-east-1' +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: nodejs12.x + Events: + Fetch: + Type: Api + Properties: + RestApiId: !Ref MyApi + Method: Post + Path: /fetch + + MyApi: + Type: AWS::Serverless::Api + Properties: + OpenApiVersion: 3.0.1 + StageName: Prod + Domain: + DomainName: !Ref DomainName + CertificateArn: !Ref ACMCertificateArn + EndpointConfiguration: EDGE + BasePath: + - /one + Route53: + HostedZoneName: www.my-domain.com. + IpV6: true \ No newline at end of file diff --git a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json new file mode 100644 index 0000000000..030230858a --- /dev/null +++ b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json @@ -0,0 +1,197 @@ +{ + "Parameters": { + "ACMCertificateArn": { + "Default": "cert-arn-in-us-east-1", + "Type": "String" + }, + "DomainName": { + "Default": "example.com", + "Type": "String" + } + }, + "Resources": { + "MyFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "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" + }, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFunctionFetchPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + } + }, + "ApiGatewayDomainName0caaf24ab1": { + "Type": "AWS::ApiGateway::DomainName", + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + }, + "DomainName": "example.com" + } + }, + "RecordSetGroup456ebaf280": { + "Type": "AWS::Route53::RecordSetGroup", + "Properties": { + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "A", + "Name": "example.com" + }, + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "AAAA", + "Name": "example.com" + } + ] + } + }, + "MyApiDeploymentf643ef7f59": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApi" + }, + "Description": "RestApi deployment id: f643ef7f592a69a57638dd25e64dc12d2b4abf2d" + } + }, + "MyApioneBasePathMapping": { + "Type": "AWS::ApiGateway::BasePathMapping", + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + } + }, + "MyApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentf643ef7f59" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + } + }, + "MyFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/fetch": { + "post": { + "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" + } + }, + "responses": {} + } + } + }, + "openapi": "3.0.1" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json new file mode 100644 index 0000000000..98dbfcf6c1 --- /dev/null +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json @@ -0,0 +1,205 @@ +{ + "Parameters": { + "ACMCertificateArn": { + "Default": "cert-arn-in-us-east-1", + "Type": "String" + }, + "DomainName": { + "Default": "example.com", + "Type": "String" + } + }, + "Resources": { + "MyFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "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" + }, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFunctionFetchPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + } + }, + "ApiGatewayDomainName0caaf24ab1": { + "Type": "AWS::ApiGateway::DomainName", + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + }, + "DomainName": "example.com" + } + }, + "RecordSetGroup456ebaf280": { + "Type": "AWS::Route53::RecordSetGroup", + "Properties": { + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "A", + "Name": "example.com" + }, + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "AAAA", + "Name": "example.com" + } + ] + } + }, + "MyApioneBasePathMapping": { + "Type": "AWS::ApiGateway::BasePathMapping", + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + } + }, + "MyApiDeploymentfb330328f1": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApi" + }, + "Description": "RestApi deployment id: fb330328f152e4bb4b7d68e8b976b009e0558035" + } + }, + "MyApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentfb330328f1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + } + }, + "MyFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/fetch": { + "post": { + "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" + } + }, + "responses": {} + } + } + }, + "openapi": "3.0.1" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json index d5b4503f3a..362045c0b4 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json @@ -1,50 +1,50 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", + "Handler": "index.handler", "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" - }, + }, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } @@ -52,88 +52,88 @@ ] } } - }, + }, "MyApiDeployment1deeaff693": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApi" - }, + }, "Description": "RestApi deployment id: 1deeaff6933b892391de7a35e4cf92e79a47aea9" } - }, + }, "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", + "Type": "AWS::Route53::RecordSetGroup", "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", + "HostedZoneId": "ZQ1UAL4EFZVME", "RecordSets": [ { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", + "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] } - }, - "Type": "A", + }, + "Type": "A", "Name": "example.com" - }, + }, { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", + "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] } - }, - "Type": "AAAA", + }, + "Type": "AAAA", "Name": "example.com" } ] } - }, + }, "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { - "BasePath": "one", + "BasePath": "one", "DomainName": { "Ref": "ApiGatewayDomainName0caaf24ab1" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "Stage": { "Ref": "MyApiProdStage" } } - }, + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment1deeaff693" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" } - }, + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -141,61 +141,61 @@ } } ] - }, + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", + "Type": "AWS::ApiGateway::DomainName", "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", + "CertificateArn": "cert-arn-in-us-east-1", "EndpointConfiguration": { "Types": [ "EDGE" ] - }, + }, "DomainName": "example.com" } - }, + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/fetch": { "post": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + }, "responses": {} } } - }, + }, "openapi": "3.0.1" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json new file mode 100644 index 0000000000..b551a1cbd1 --- /dev/null +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json @@ -0,0 +1,205 @@ +{ + "Parameters": { + "ACMCertificateArn": { + "Default": "cert-arn-in-us-east-1", + "Type": "String" + }, + "DomainName": { + "Default": "example.com", + "Type": "String" + } + }, + "Resources": { + "MyFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "index.handler", + "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" + }, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MyFunctionFetchPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", + "FunctionName": { + "Ref": "MyFunction" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__Stage__": "*", + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + } + }, + "MyApiDeployment1deeaff693": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApi" + }, + "Description": "RestApi deployment id: 1deeaff6933b892391de7a35e4cf92e79a47aea9" + } + }, + "RecordSetGroup456ebaf280": { + "Type": "AWS::Route53::RecordSetGroup", + "Properties": { + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "A", + "Name": "example.com" + }, + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "AAAA", + "Name": "example.com" + } + ] + } + }, + "MyApioneBasePathMapping": { + "Type": "AWS::ApiGateway::BasePathMapping", + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + } + }, + "MyApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment1deeaff693" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + } + }, + "MyFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ApiGatewayDomainName0caaf24ab1": { + "Type": "AWS::ApiGateway::DomainName", + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + }, + "DomainName": "example.com" + } + }, + "MyApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/fetch": { + "post": { + "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" + } + }, + "responses": {} + } + } + }, + "openapi": "3.0.1" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 54373f86a7..7d5c52b800 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -338,6 +338,7 @@ def test_transform_success(self, testcase, partition_with_region): "api_with_basic_custom_domain", "api_with_basic_custom_domain_intrinsics", "api_with_custom_domain_route53", + "api_with_custom_domain_route53_hosted_zone_name", "implicit_http_api", "explicit_http_api_minimum", "implicit_http_api_auth_and_simple_case", @@ -355,6 +356,7 @@ def test_transform_success(self, testcase, partition_with_region): ], # Run all the above tests against each of the list of partitions to test against ) ) + @pytest.mark.slow @patch( "samtranslator.plugins.application.serverless_app_plugin.ServerlessAppPlugin._sar_service_call", mock_sar_service_call, From 23b4c649182314d4868accb83d95a5e2e63b8568 Mon Sep 17 00:00:00 2001 From: "Michael Barney, Jr" Date: Thu, 23 Jan 2020 15:27:50 -0500 Subject: [PATCH 5/7] ran make black --- bin/sam-translate.py | 2 +- samtranslator/model/api/api_generator.py | 7 +++++-- samtranslator/model/sam_resources.py | 13 ++++++++++--- .../test_deployment_preference_collection.py | 4 ++-- tests/translator/test_api_resource.py | 2 +- tests/translator/test_translator.py | 12 ++++++------ tests/translator/validator/test_validator.py | 4 ++-- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bin/sam-translate.py b/bin/sam-translate.py index 5c0c7ede2f..bffb9fe84f 100755 --- a/bin/sam-translate.py +++ b/bin/sam-translate.py @@ -101,7 +101,7 @@ def transform_template(input_file_path, output_file_path): with open(output_file_path, "w") as f: f.write(cloud_formation_template_prettified) - print ("Wrote transformed CloudFormation template to: " + output_file_path) + print("Wrote transformed CloudFormation template to: " + output_file_path) except InvalidDocumentException as e: errorMessage = reduce(lambda message, error: message + " " + error.message, e.causes, e.message) LOG.error(errorMessage) diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 856992f3df..fcaf689e4c 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -340,9 +340,12 @@ def _construct_api_domain(self, rest_api): route53 = self.domain.get("Route53") if route53.get("HostedZoneId") is None and route53.get("HostedZoneName") is None: raise InvalidResourceException( - self.logical_id, "HostedZoneId or HostedZoneName is required to enable Route53 support on Custom Domains." + self.logical_id, + "HostedZoneId or HostedZoneName is required to enable Route53 support on Custom Domains.", ) - logical_id = logical_id_generator.LogicalIdGenerator("", route53.get("HostedZoneId") or route53.get("HostedZoneName")).gen() + logical_id = logical_id_generator.LogicalIdGenerator( + "", route53.get("HostedZoneId") or route53.get("HostedZoneName") + ).gen() record_set_group = Route53RecordSetGroup( "RecordSetGroup" + logical_id, attributes=self.passthrough_resource_attributes ) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 27744a7374..789b136383 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -799,9 +799,16 @@ def to_cloudformation(self, **kwargs): domain=self.Domain, ) - rest_api, deployment, stage, permissions, domain, basepath_mapping, route53, usage_plan_resources = api_generator.to_cloudformation( - redeploy_restapi_parameters - ) + ( + rest_api, + deployment, + stage, + permissions, + domain, + basepath_mapping, + route53, + usage_plan_resources, + ) = api_generator.to_cloudformation(redeploy_restapi_parameters) resources.extend([rest_api, deployment, stage]) resources.extend(permissions) diff --git a/tests/translator/model/preferences/test_deployment_preference_collection.py b/tests/translator/model/preferences/test_deployment_preference_collection.py index 6307248087..ae8b39bdc8 100644 --- a/tests/translator/model/preferences/test_deployment_preference_collection.py +++ b/tests/translator/model/preferences/test_deployment_preference_collection.py @@ -104,7 +104,7 @@ def test_deployment_preference_with_codedeploy_predifined_configuration(self): deployment_preference_collection.add(self.function_logical_id, {"Type": deployment_type}) deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) - print (deployment_group.DeploymentConfigName) + print(deployment_group.DeploymentConfigName) self.assertEqual(expected_deployment_config_name, deployment_group.DeploymentConfigName) @patch("boto3.session.Session.region_name", "ap-southeast-1") @@ -133,7 +133,7 @@ def test_deployment_preference_with_conditional_custom_configuration(self): deployment_preference_collection = DeploymentPreferenceCollection() deployment_preference_collection.add(self.function_logical_id, {"Type": deployment_type}) deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) - print (deployment_group.DeploymentConfigName) + print(deployment_group.DeploymentConfigName) self.assertEqual(expected_deployment_config_name, deployment_group.DeploymentConfigName) @patch("boto3.session.Session.region_name", "ap-southeast-1") diff --git a/tests/translator/test_api_resource.py b/tests/translator/test_api_resource.py index 30c3b2086e..41be5fddb0 100644 --- a/tests/translator/test_api_resource.py +++ b/tests/translator/test_api_resource.py @@ -96,7 +96,7 @@ def test_redeploy_implicit_api(): def translate_and_find_deployment_ids(manifest): parameter_values = get_template_parameter_values() output_fragment = transform(manifest, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) deployment_ids = set() for key, value in output_fragment["Resources"].items(): diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 7d5c52b800..6dc2d86e3d 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -312,7 +312,7 @@ def test_transform_success(self, testcase, partition_with_region): output_fragment = transform(manifest, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) # Only update the deployment Logical Id hash in Py3. if sys.version_info.major >= 3: @@ -387,7 +387,7 @@ def test_transform_success_openapi3(self, testcase, partition_with_region): output_fragment = transform(manifest, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) # Only update the deployment Logical Id hash in Py3. if sys.version_info.major >= 3: @@ -445,7 +445,7 @@ def test_transform_success_resource_policy(self, testcase, partition_with_region } output_fragment = transform(manifest, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) # Only update the deployment Logical Id hash in Py3. if sys.version_info.major >= 3: @@ -708,7 +708,7 @@ def test_swagger_body_sha_gets_recomputed(): output_fragment = transform(document, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) deployment_key = get_deployment_key(output_fragment) assert deployment_key @@ -744,7 +744,7 @@ def test_swagger_definitionuri_sha_gets_recomputed(): output_fragment = transform(document, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) deployment_key = get_deployment_key(output_fragment) assert deployment_key @@ -826,7 +826,7 @@ def _do_transform(self, document, parameter_values=get_template_parameter_values mock_policy_loader = get_policy_mock() output_fragment = transform(document, parameter_values, mock_policy_loader) - print (json.dumps(output_fragment, indent=2)) + print(json.dumps(output_fragment, indent=2)) return output_fragment diff --git a/tests/translator/validator/test_validator.py b/tests/translator/validator/test_validator.py index d76aa94eaa..ad6d142669 100644 --- a/tests/translator/validator/test_validator.py +++ b/tests/translator/validator/test_validator.py @@ -117,6 +117,6 @@ def test_validate_template_success(testcase): validation_errors = SamTemplateValidator.validate(manifest) has_errors = len(validation_errors) if has_errors: - print ("\nFailing template: {0}\n".format(testcase)) - print (validation_errors) + print("\nFailing template: {0}\n".format(testcase)) + print(validation_errors) assert len(validation_errors) == 0 From a975312228871f7be8c384a25e1317ca0149cd6a Mon Sep 17 00:00:00 2001 From: "Michael Barney, Jr" Date: Fri, 24 Jan 2020 09:19:57 -0500 Subject: [PATCH 6/7] Fixed broken test --- .../output/error_api_with_custom_domains_route53_invalid.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/translator/output/error_api_with_custom_domains_route53_invalid.json b/tests/translator/output/error_api_with_custom_domains_route53_invalid.json index 5f21a0ab82..1e55a56556 100644 --- a/tests/translator/output/error_api_with_custom_domains_route53_invalid.json +++ b/tests/translator/output/error_api_with_custom_domains_route53_invalid.json @@ -4,5 +4,5 @@ "errorMessage": "Resource with id [MyApi] is invalid. HostedZoneId is required to enable Route53 support on Custom Domains." } ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. HostedZoneId is required to enable Route53 support on Custom Domains." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. HostedZoneId or HostedZoneName is required to enable Route53 support on Custom Domains." } From 71d311205fbe186853324b9d052ec6fe2431e631 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Fri, 31 Jan 2020 09:30:23 -0800 Subject: [PATCH 7/7] Fix failing tests --- ...ustom_domain_route53_hosted_zone_name.json | 218 +++++++++--------- ...ustom_domain_route53_hosted_zone_name.json | 182 +++++++-------- ...ustom_domain_route53_hosted_zone_name.json | 178 +++++++------- 3 files changed, 289 insertions(+), 289 deletions(-) diff --git a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json index 030230858a..85799af333 100644 --- a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json +++ b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json @@ -1,50 +1,50 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", + "Handler": "index.handler", "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" - }, + }, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } @@ -52,100 +52,85 @@ ] } } - }, + }, "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", + "Type": "AWS::ApiGateway::DomainName", "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", + "CertificateArn": "cert-arn-in-us-east-1", "EndpointConfiguration": { "Types": [ "EDGE" ] - }, + }, "DomainName": "example.com" } - }, - "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneName": "www.my-domain.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" - } - ] - } - }, - "MyApiDeploymentf643ef7f59": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyApiProdStage": { + "Type": "AWS::ApiGateway::Stage", "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymenteb58d7577a" + }, "RestApiId": { "Ref": "MyApi" - }, - "Description": "RestApi deployment id: f643ef7f592a69a57638dd25e64dc12d2b4abf2d" + }, + "StageName": "Prod" } - }, + }, "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { - "BasePath": "one", + "BasePath": "one", "DomainName": { "Ref": "ApiGatewayDomainName0caaf24ab1" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "Stage": { "Ref": "MyApiProdStage" } } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "MyApi": { + "Type": "AWS::ApiGateway::RestApi", "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentf643ef7f59" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/fetch": { + "post": { + "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" + } + }, + "responses": {} + } + } + }, + "openapi": "3.0.1" + } } - }, + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -153,44 +138,59 @@ } } ] - }, + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "RecordSetGroup456ebaf280": { + "Type": "AWS::Route53::RecordSetGroup", "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "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" - } - }, - "responses": {} + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] } - } - }, - "openapi": "3.0.1" - } + }, + "Type": "A", + "Name": "example.com" + }, + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "AAAA", + "Name": "example.com" + } + ] + } + }, + "MyApiDeploymenteb58d7577a": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyApi" + }, + "Description": "RestApi deployment id: eb58d7577a65af049c9c6f10c9d8b286de6b5aeb" } } } diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json index 98dbfcf6c1..98a21b9e22 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json @@ -1,50 +1,50 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", + "Handler": "index.handler", "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" - }, + }, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } @@ -52,100 +52,66 @@ ] } } - }, + }, "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", + "Type": "AWS::ApiGateway::DomainName", "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", + "CertificateArn": "cert-arn-in-us-east-1", "EndpointConfiguration": { "Types": [ "EDGE" ] - }, + }, "DomainName": "example.com" } - }, - "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "MyApiDeployment9239fa9a13": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { - "HostedZoneName": "www.my-domain.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" - } - ] + "RestApiId": { + "Ref": "MyApi" + }, + "Description": "RestApi deployment id: 9239fa9a13216200ab5bf11c04507c61842a50a7" } - }, + }, "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { - "BasePath": "one", + "BasePath": "one", "DomainName": { "Ref": "ApiGatewayDomainName0caaf24ab1" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "Stage": { "Ref": "MyApiProdStage" } } - }, - "MyApiDeploymentfb330328f1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: fb330328f152e4bb4b7d68e8b976b009e0558035" - } - }, + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiDeploymentfb330328f1" - }, + "Ref": "MyApiDeployment9239fa9a13" + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" } - }, + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -153,49 +119,83 @@ } } ] - }, + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, + "RecordSetGroup456ebaf280": { + "Type": "AWS::Route53::RecordSetGroup", + "Properties": { + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "A", + "Name": "example.com" + }, + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "AAAA", + "Name": "example.com" + } + ] + } + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/fetch": { "post": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + }, "responses": {} } } - }, + }, "openapi": "3.0.1" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json index b551a1cbd1..5445e4f69e 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json @@ -1,50 +1,50 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", + "Handler": "index.handler", "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" - }, + }, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", + "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } @@ -52,88 +52,54 @@ ] } } - }, - "MyApiDeployment1deeaff693": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyApiDeployment501f2306c4": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 1deeaff6933b892391de7a35e4cf92e79a47aea9" + }, + "Description": "RestApi deployment id: 501f2306c4860ed198c3020aa43d453cdbdd6b7a" } - }, - "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneName": "www.my-domain.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" - } - ] - } - }, + }, "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { - "BasePath": "one", + "BasePath": "one", "DomainName": { "Ref": "ApiGatewayDomainName0caaf24ab1" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "Stage": { "Ref": "MyApiProdStage" } } - }, + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyApiDeployment1deeaff693" - }, + "Ref": "MyApiDeployment501f2306c4" + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" } - }, + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -141,61 +107,95 @@ } } ] - }, + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", + "Type": "AWS::ApiGateway::DomainName", "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", + "CertificateArn": "cert-arn-in-us-east-1", "EndpointConfiguration": { "Types": [ "EDGE" ] - }, + }, "DomainName": "example.com" } - }, + }, + "RecordSetGroup456ebaf280": { + "Type": "AWS::Route53::RecordSetGroup", + "Properties": { + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "A", + "Name": "example.com" + }, + { + "AliasTarget": { + "HostedZoneId": "Z2FDTNDATAQYW2", + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + } + }, + "Type": "AAAA", + "Name": "example.com" + } + ] + } + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", + "version": "1.0", "title": { "Ref": "AWS::StackName" } - }, + }, "paths": { "/fetch": { "post": { "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + }, "responses": {} } } - }, + }, "openapi": "3.0.1" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" }