amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

CFN template in yaml or json format

Open timoteialbu opened this issue 7 years ago • 13 comments

Note: If your feature-request is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum

Is your feature request related to a problem? Please describe. I like to use yaml whenever possible. Its shorter to write and easier on the eyes.

Describe the solution you'd like I would like for the CLI so support the yaml format, particularly for the cloudfront hosting. The yaml templates work up to a point, like I can update the cloudfront with it, but when it gets to the step where it publishes my react app it fails. It says it cannot find a template.json file, which is true since I have a template.yaml file. The "issue" is on this line: https://github.com/aws-amplify/amplify-cli/blob/master/packages/amplify-category-hosting/lib/S3AndCloudFront/index.js#L120 If you guys could have a file reader that works for both yaml and json that would be great.

Describe alternatives you've considered Alternatives would be to go back to JSON, which is what I will do in the meantime. But it would be nice to have this feature, cause you guys say that formats are not enforced: https://github.com/aws-amplify/amplify-cli/issues/1286 (I know its related to Cognito there)

Additional context Add any other context or screenshots about the feature request here.

timoteialbu avatar Jul 26 '19 17:07 timoteialbu

@timoteialbu Thanks for the feedbacks. The team will have a discussion and update you on this.

UnleashedMind avatar Jul 26 '19 18:07 UnleashedMind

Thanks, looking forward to your response.

timoteialbu avatar Jul 30 '19 21:07 timoteialbu

Any update on this? Can we use YAML for our custom stacks yet in Amplify?

UPDATE: You can also install cfn-flip (it is an AWS managed utility) to convert YAML to JSON. I keep my YAML files in ./amplify/backend/{category}/{name}/stacks-yaml, and then before I run an amplify push, I run cfn-flip and output all JSON files to the prescribed ./stacks directory. I can see how difficult it would be to incorporate a YAML parser into this project though because there's a lot of custom operator/logic, and you need JSON to merge all of the custom/boilerplate stacks.

Hope this ultimately gets in there in an automated fashion, but for now, this works!

kevcam4891 avatar Sep 10 '19 00:09 kevcam4891

@kevinc1984 That's exactly what I do. Convert to yaml, make my changes and then convert back. It would just be nice to support both, since amplify could do that conversion on their side, merge the JSON stuff and then output it back into the format I had.

timoteialbu avatar Sep 11 '19 22:09 timoteialbu

FWIW I'm using YAML for my custom stacks right now (since 4.0.0) and it "just works"

rowanu avatar Nov 29 '19 01:11 rowanu

@rowanu what do you mean "just works"? I put a .yml file in my stacks directory and I get:

Yaml is not yet supported. Please convert the CloudFormation stack my-stack.yml to json.

berenddeboer avatar Dec 26 '19 21:12 berenddeboer

I created a custom stack template in YAML, and put it in the path ./amplify/backend/{category}/{name}/{name}-cloudformation-template.yaml and it is deployed with an amplify push.

rowanu avatar Dec 27 '19 00:12 rowanu

@rowanu that doesn't do anything for me. You're sure it is deployed?If it is, it's because something else going on on your system.

berenddeboer avatar Dec 27 '19 22:12 berenddeboer

The only other steps I followed were those for custom CloudFormation stacks in the CLI docs 🤷‍♂

rowanu avatar Dec 28 '19 23:12 rowanu

YAML didn't work for me either, using Amplify CLI 4.16.1. It failed with:

SyntaxError: Unexpected token A in JSON at position 0 at JSON.parse () at AmplifyToolkit.readJsonFile [as _readJsonFile] (/usr/local/lib/node_modules/@aws-amplify/cli/src/extensions/amplify-helpers/read-json-file.js:11:15) at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/push-resources.js:250:41

I resorted to conversion from YAML to JSON before build, with automation so it's seamless, using "postinstall" in package.json:

"scripts": { "postinstall": "cfn-flip cloudformation-template.yaml | tee ../yaml_converted_template.json" }

cfn-flip is taken from https://github.com/awslabs/aws-cfn-template-flip To make it work on AWS Amplify Console, I created an executable with pyinstaller and checked it in my repo: docker run --rm -v $PWD:/foo/dist -w /foo amazonlinux:2 ./dist/package_cfn_flip.sh cfn-flip

where package_cfn_flip.sh (located in $PWD) is:

#!/bin/bash -ex yum install -y python3 binutils python3 -m venv venv source venv/bin/activate pip3 install pyinstaller cfn_flip echo "from cfn_flip import flip; import sys; print(flip(open(sys.argv[1], 'r').read()))" > cfnflip.py pyinstaller --onefile --name $1 cfnflip.py deactivate rm -rf venv

qtangs avatar Mar 25 '20 08:03 qtangs

Still not working entirely on Amplify 4.29. Works with push, not with publish:

Publish started for S3AndCloudFront
File at path: '.../amplify/backend/hosting/S3AndCloudFront/template.json' does not exist

I have a template.yaml, but template.yml doesn't work either.

berenddeboer avatar Sep 11 '20 05:09 berenddeboer

Closing in favor of existing feature request - Feature request: Use YAML for all CloudFormation files.

siegerts avatar May 26 '21 14:05 siegerts

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar Jul 26 '21 01:07 github-actions[bot]