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

CFN template in yaml or json format #1904

Closed
timoteialbu opened this issue Jul 26, 2019 · 13 comments
Closed

CFN template in yaml or json format #1904

timoteialbu opened this issue Jul 26, 2019 · 13 comments
Labels
feature-request Request a new feature

Comments

@timoteialbu
Copy link

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: #1286 (I know its related to Cognito there)

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

@UnleashedMind UnleashedMind added enhancement hosting Issues tied to hosting category pending-review Pending review from core-team labels Jul 26, 2019
@UnleashedMind
Copy link
Contributor

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

@timoteialbu
Copy link
Author

Thanks, looking forward to your response.

@kevcam4891
Copy link
Contributor

kevcam4891 commented Sep 10, 2019

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!

@timoteialbu
Copy link
Author

@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.

@rowanu
Copy link
Contributor

rowanu commented Nov 29, 2019

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

@berenddeboer
Copy link

berenddeboer commented Dec 26, 2019

@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.

@rowanu
Copy link
Contributor

rowanu commented Dec 27, 2019

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.

@berenddeboer
Copy link

@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.

@rowanu
Copy link
Contributor

rowanu commented Dec 28, 2019

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

@qtangs
Copy link

qtangs commented Mar 25, 2020

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

@berenddeboer
Copy link

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.

@siegerts siegerts removed hosting Issues tied to hosting category pending-review Pending review from core-team labels May 26, 2021
@siegerts
Copy link
Contributor

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

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2021
@josefaidt josefaidt added feature-request Request a new feature and removed enhancement labels Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

8 participants