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
cli command to transform sam template to regular cloudformation template? #1141
Comments
@rhbecker Thanks for the issue. Marking as a feature request. We surface the generated template in |
I tried out the One issue I'll point out: The output it produced included anchors and aliases, which are apparently not supported by cloudformation. It was easy enough to manually edit in order to remove, but as part of this feature request, it would be ideal for the output of an added |
I'd like to weight in favor of this feature request as Transforms are not yet supported by StackSets as of Jan 2020: |
Our group could also use this. Developers do a SAM build for local testing, but cloud engineers maintain a separate Cloud Formation template for deployment. Generating the CF template would reduce work and errors. |
Another upvote. I would want to use the SAM CLI to generate the CF template to be then aggregated as a child template in a parent application stack. |
Not a native CLI command but I found this script very helpful |
To get the final CloudFormation template that will be deployed, you can also get the change set with: sam deploy --no-execute-changeset Then get the processed template with: aws cloudformation get-template --query TemplateBody --change-set-name <change-set-arn> Or save this (not prod-ready) as import json
import sys
import uuid
import boto3
def transform(template: str) -> str:
cfn = boto3.client("cloudformation")
name = f"transform-{uuid.uuid4()}"
change_set = cfn.create_change_set(
TemplateBody=template,
StackName=name,
ChangeSetName=name,
ChangeSetType="CREATE",
Capabilities=[
"CAPABILITY_IAM",
"CAPABILITY_AUTO_EXPAND",
],
)
change_set_id = change_set["Id"]
waiter = cfn.get_waiter("change_set_create_complete")
waiter.wait(
ChangeSetName=change_set_id,
WaiterConfig={
"Delay": 5,
},
)
transformed = cfn.get_template(ChangeSetName=change_set_id)
cfn.delete_stack(StackName=name)
return json.dumps(transformed["TemplateBody"])
def main():
print(transform(sys.stdin.read()))
if __name__ == "__main__":
main() Then transform using: python transform.py < sam-template.yaml > cfn-template.json |
Wrote a Nix flake for the translator app: Run like this:
|
I'm using this method: https://github.com/aws/serverless-application-model/blob/develop/bin/sam-translate.py |
Describe your idea/feature/enhancement
I believe it could be useful to add a command to allow a user to see the cloudformation template produced after serverless transforms are applied.
Proposal
sam transform --template-file PATH --output-template-file PATH
Additional Details
A couple reasons I see value here:
education - for a new user, there's mystery around the effects of using sam syntax ... e.g. what policies are going to be automatically generated based on various properties i specify
some mechanisms in the wild are not yet friendly towards serverless transforms and being able to provide them with vanilla cloudformation, while still taking advantage of sam syntax during compose phase is a nice compromise
The text was updated successfully, but these errors were encountered: