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 Thanks for the feedbacks.
The team will have a discussion and update you on this.
Thanks, looking forward to your response.
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!
@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.
FWIW I'm using YAML for my custom stacks right now (since 4.0.0) and it "just works"
@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.
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 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.
The only other steps I followed were those for custom CloudFormation stacks in the CLI docs 馃し鈥嶁檪
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
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.
Most helpful comment
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 runcfn-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!