Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format of CloudFormation template that uses Fn::Transform yields invalid template #59

Closed
tomirio619 opened this issue Apr 22, 2021 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@tomirio619
Copy link

tomirio619 commented Apr 22, 2021

I have the following CloudFormation snippet called input.yml:

Resources:
  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      ApiKeySourceType: HEADER
      Body:
        Fn::Transform:
          Name: AWS::Include
          Parameters:
            Location: s3://<bucket-name>/<object-key>
      Description: API
      EndpointConfiguration:
        Types:
          - PRIVATE
      FailOnWarnings: true
      Name: My API

When I run $ rain fmt input.yml > output.yml, the contents of output.yml are:

AWSTemplateFormatVersion: "2010-09-09"

Resources:
  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      ApiKeySourceType: HEADER
      Body: !Transform
        Name: AWS::Include
        Parameters:
          Location: s3://<bucket-name>/<object-key>
      Description: My API
      EndpointConfiguration:
        Types:
          - PRIVATE
      FailOnWarnings: true
      Name: API

If I deploy this formatted template in CloudFormation, deployment fails with the following message:

An error occurred (ValidationError) when calling the ValidateTemplate operation: Template format error: YAML not well-formed. 

Unfortunately, I cannot make use of S3BodyLocation (instead of Body), as our OpenAPI specification contains CloudFormation functions which are not substituted when used with S3BodyLocation (see this issue).
If used, the following message is shown for the CREATE_FAILED status:

Unable to parse API definition because of a malformed integration at path /an/example/path. (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: REDACTED; Proxy: null)

The AWS::Include transform documentation could be related, as it mentions the following:

We don't currently support using shorthand notations for YAML snippets.
@tomirio619 tomirio619 changed the title Format of CloudFormation template that uses Fn::Transform within a section yields invalid template Format of CloudFormation template that uses Fn::Transform invalid template Apr 22, 2021
@tomirio619 tomirio619 changed the title Format of CloudFormation template that uses Fn::Transform invalid template Format of CloudFormation template that uses Fn::Transform yields invalid template Apr 22, 2021
@stilvoid
Copy link
Member

Thanks for this! After some digging, it seems the Transform function just doesn't support the YAML tag-style notation. I will prevent Fn::Transform from being modified by rain fmt in the next release.

@stilvoid stilvoid added the bug Something isn't working label Apr 29, 2021
@stilvoid stilvoid added this to the 1.3.0 milestone Apr 29, 2021
@stilvoid
Copy link
Member

Fixed in dd5001e

@tomirio619
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants