aws / aws/aws-sam-cli

sam deploy: Support `-` which indicates stdin

Open
#2,990 2 comments 5 reactions 0 assignees View on GitHub
maintainer/need-followup stage/pm-review type/feature
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### 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=

$ 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.