Skip to content

adds capability to resolve anchors and aliases in yaml in aws cloudformation package - #3462

Closed
shortjared wants to merge 1 commit into
aws:developfrom
shortjared:feature/yaml-anchors-and-aliases
Closed

shortjared wants to merge 1 commit into
aws:developfrom
shortjared:feature/yaml-anchors-and-aliases

Conversation

@shortjared

Copy link
Copy Markdown

Issue #, if available:

No issue number specifically, but this has been mentioned before in several cases and a feature folks have wanted natively in CloudFormation but we aren't going to get anytime soon.

Description of changes:

This simply enhances the yaml parser used to resolve anchors and aliases to a non-referential structure. This lets you do a little bit DRYing up your templates without any external tooling. This should be fully backwards compatible and you only need to use it if you want to.

Important to note, this is doing nothing that nearly all other yaml libs can't do. Take the below template for example and plug it in to http://yaml-online-parser.appspot.com and you'll get perfectly valid json outputs with no additional logic. Of course, you would still need aws cloudformation package to populate the CodeUri but that is a different process.

Also note, the usage of the Metadata section is inconsequential. It's just an easy place to put stuff without impacting the template. You could just as well anchor to the first instance of properties on your actual resource instance.

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: A starter AWS Lambda function.

Metadata:
  Templates:
    Resources:
      Properties: &Props
        Handler: lambda_function.lambda_handler
        Runtime: python3.6
        CodeUri: .
        Description: A starter AWS Lambda function.
        MemorySize: 128
        Timeout: 3

Resources:
  helloworldpython3:
    Type: 'AWS::Serverless::Function'
    Properties:
      <<: *Props

  helloworldnode:
    Type: 'AWS::Serverless::Function'
    Properties:
      <<: *Props
      Runtime: nodejs8.10

Example output from aws cloudformation package in this case would be

AWSTemplateFormatVersion: '2010-09-09'
Description: A starter AWS Lambda function.
Metadata:
  Templates:
    Resources:
      Properties:
        CodeUri: .
        Description: A starter AWS Lambda function.
        Handler: lambda_function.lambda_handler
        MemorySize: 128
        Runtime: python3.6
        Timeout: 3
Resources:
  helloworldnode:
    Properties:
      CodeUri: s3://serverless-deployments-us-east-1-123456789101/ec854419bcd553ab2fa06d17aa10f7c9
      Description: A starter AWS Lambda function.
      Handler: lambda_function.lambda_handler
      MemorySize: 128
      Runtime: nodejs8.10
      Timeout: 3
    Type: AWS::Serverless::Function
  helloworldpython3:
    Properties:
      CodeUri: s3://serverless-deployments-us-east-1-123456789101/ec854419bcd553ab2fa06d17aa10f7c9
      Description: A starter AWS Lambda function.
      Handler: lambda_function.lambda_handler
      MemorySize: 128
      Runtime: python3.6
      Timeout: 3
    Type: AWS::Serverless::Function
Transform: AWS::Serverless-2016-10-31

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #3462 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3462      +/-   ##
===========================================
+ Coverage    94.54%   94.54%   +<.01%     
===========================================
  Files          174      174              
  Lines        13395    13398       +3     
===========================================
+ Hits         12664    12667       +3     
  Misses         731      731
Impacted Files Coverage Δ
awscli/customizations/cloudformation/yamlhelper.py 100% <100%> (ø) ⬆️

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 0d2d55e...e2273a6. Read the comment docs.

@jfuss

jfuss commented Sep 27, 2018

Copy link
Copy Markdown

I have commented on AWS SAM CLI's PR that was linked to this but the reasons hold true here as well.

You can see detailed comments on why the PR was not accepted here.

TLDR:
Their is a requirement that a template with the Transform of AWS::Serverless-2016-10-31 needs to be deployable through CloudFormation. This change will break that requirement.

@mswilson

Copy link
Copy Markdown

Obsoleted by #3827 ?

@shortjared shortjared closed this Sep 29, 2020
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