Skip to content

Fix route53 record set groups#2408

Merged
hawflau merged 6 commits into
aws:developfrom
hawflau:fix-route53-record-set
Jul 8, 2022
Merged

Fix route53 record set groups#2408
hawflau merged 6 commits into
aws:developfrom
hawflau:fix-route53-record-set

Conversation

@hawflau

@hawflau hawflau commented May 31, 2022

Copy link
Copy Markdown
Contributor

Issue #, if available:
#1829

Description of changes:
Keep track of created AWS::Route53::RecordSetGroup resources in a cache. If a logical ID is already contained in the cache, use the created one and append a record set into it. Otherwise, create a new AWS::Route53::RecordSetGroup for that logical ID and keep it in the cache.

Description of how you validated changes:

  • Added e2e test (tests/translator/input/api_with_custom_domain_route53_multiple.yaml) to confirm the template is transformed as expected

Checklist:

  • Add/update unit tests using:
  • Add/update integration tests
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected
  • Do these changes include any template validations?
    • Did the newly validated properties support intrinsics prior to adding the validations? (If unsure, please review Intrinsic Functions before proceeding).
      • Does the pull request ensure that intrinsics remain functional with the new validations?

Examples?

Please reach out in the comments, if you want to add an example. Examples will be
added to sam init through https://github.com/awslabs/aws-sam-cli-app-templates/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@hawflau
hawflau marked this pull request as ready for review June 9, 2022 21:52
@codecov-commenter

codecov-commenter commented Jun 9, 2022

Copy link
Copy Markdown

Codecov Report

Merging #2408 (0989ee1) into develop (e7a1496) will increase coverage by 0.89%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop    #2408      +/-   ##
===========================================
+ Coverage    93.58%   94.47%   +0.89%     
===========================================
  Files           90       98       +8     
  Lines         6124     7280    +1156     
  Branches      1260     1514     +254     
===========================================
+ Hits          5731     6878    +1147     
- Misses         183      194      +11     
+ Partials       210      208       -2     
Impacted Files Coverage Δ
samtranslator/region_configuration.py 77.77% <0.00%> (-22.23%) ⬇️
samtranslator/model/codedeploy.py 90.90% <0.00%> (-9.10%) ⬇️
samtranslator/validator/validator.py 91.80% <0.00%> (-3.85%) ⬇️
samtranslator/model/exceptions.py 97.67% <0.00%> (-2.33%) ⬇️
samtranslator/open_api/open_api.py 90.16% <0.00%> (-1.81%) ⬇️
samtranslator/model/s3_utils/uri_parser.py 68.42% <0.00%> (-0.81%) ⬇️
samtranslator/yaml_helper.py 89.47% <0.00%> (-0.53%) ⬇️
samtranslator/translator/logical_id_generator.py 90.62% <0.00%> (-0.29%) ⬇️
samtranslator/model/apigateway.py 96.98% <0.00%> (-0.18%) ⬇️
samtranslator/intrinsics/resource_refs.py 95.83% <0.00%> (-0.17%) ⬇️
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24fd3a1...0989ee1. Read the comment docs.

@jfuss jfuss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes to discuss comments. Overall the PR looks good though.

Comment thread samtranslator/model/api/api_generator.py Outdated
shared_api_usage_plan = SharedApiUsagePlan()
document_errors = []
changed_logical_ids = {}
route53_record_set_groups = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will combine Http and Rest Api's into one "cache". Will we run into a issue where the key used will collide between the two different resources if they are in the same template?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is the logical IDs of the generated AWS::Route53::RecordSetGroup resources. For both case of Http API and Rest API, the logical ID is generated based on either HostedZoneId or HostedZoneName. So, corresponding record set would still be appended into an existing generated record set group instead of overwriting it.
I added a test for this mixed api case.

@jfuss

jfuss commented Jun 14, 2022

Copy link
Copy Markdown
Contributor

Will this solve #1539?

@hawflau

hawflau commented Jun 17, 2022

Copy link
Copy Markdown
Contributor Author

Will this solve #1539?

Yes I believe so

CertificateArn: arn::cert::abc
EndpointConfiguration: REGIONAL
Route53:
HostedZoneId: "abc123456"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens in HostedZoneId is an intrinsic function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire HostedZoneId is used to generate a logical ID hash of the generated RecordSet Group. For example, consider HostedZoneId: !Ref MyParam, HostedZoneId: !Sub "{{MyParam}}", and HostedZoneId: "abc123456". Even if MyParamresolves to"abc123456", these three would yield RecordSet Groups with different logical ID hashes. In the case where only one kind of intrinsics is used for HostedZoneId`, only one RecordSet Group would be generated.

In the case where multiple kinds of intrinsics are used for HostedZoneId, there is no issue at well. Multiple AWS::Route53::RecordSetGroup resources can be created in a template pointing to the same HostedZoneId. For example, the template below can be deployed without any issue:

Resources:
  HostedZone:
    Type: "AWS::Route53::HostedZone"
    Properties:
      Name: "my-website.com"

  MyRecordSetGroup1:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      HostedZoneId: !Ref HostedZone
      RecordSets:
        - Name: "my-website.com"
          Type: "A"
          TTL: "900"
          ResourceRecords:
            - "101.10.21.3"

  MyRecordSetGroup2:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      HostedZoneId: !Ref HostedZone
      RecordSets:
        - Name: "www.my-website.com"
          Type: "CNAME"
          TTL: "900"
          ResourceRecords:
            - "my-website.com"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants