aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.48k stars 1.16k forks source link

sam deploy: Support `-` which indicates stdin #2990

Open conao3 opened 3 years ago

conao3 commented 3 years ago

Describe your idea/feature/enhancement

Many CLI commands can interpret - as a stdin/out. In aws-cli, s3 cp can use - as a stdin/out.

$ BUCKET=<your sample bucket>

$ echo helloworld | aws s3 cp - s3://${BUCKET}/tmp

$ aws s3 cp s3://${BUCKET}/tmp -
helloworld

If sam deploy use stdin to pass template yaml, user can use any pre process step for their template.

$ # local transform instead of Cloudformation macro
$ cat template.yml | your-favorite-transformer | sam deploy --template-file -

$ # mustache pre-process with SAM template
$ cat template.yml.mustache | mustache data.json | sam deploy --template-file -

$ # simple `sed` for SAM template (but the user should use *Parameters*.)
$ cat template.yml | sed 's/__company/aws/g' | sam deploy --template-file -

Proposal

Add details of how to add this to the product.

  1. Add a special action step if the user specifies - for --template-file option.
  2. The special action is, get template string from stdin instead of reading local file.

Things to consider:

  1. What happens when a user really wants to deal with a - file?
    • Unix command cat address - file as a ./-. So you can cat ./- if you want to see - file.
  2. Why can we assume that - implicitly indicates stdin/out? Any authoritative sources?
    • See POSIX specification: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02 "12.2 Utility Syntax Guidelines", "Guideline 13:"

      For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) or a file named -.

      Additional Details

      None

mildaniel commented 2 years ago

Thanks for the feature request! We have a roadmap here, but we also try to take in popular feature requests based on 👍🏽 from the community. We will be adding this to our intake for prioritization.

conao3 commented 2 years ago

If sam supports this feature, users will be able to use like ytt as a yaml template engine and input directly into sam without any intermediate files. https://github.com/vmware-tanzu/carvel-ytt