Skip to content

Instantly share code, notes, and snippets.

@Hogeyama
Last active May 29, 2021 12:48
Show Gist options
  • Select an option

  • Save Hogeyama/b9d857644558e86c0bb169bbd335283d to your computer and use it in GitHub Desktop.

Select an option

Save Hogeyama/b9d857644558e86c0bb169bbd335283d to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
set -o pipefail
PROGNAME="$(basename "$0")"
while [[ $# -gt 0 ]]; do
case $1 in
--command|-c)
read -ra CMD <<<"$2"
shift
;;
--gen)
GEN=1
;;
*)
FILE="$(realpath "$1")"
;;
esac
shift
done
generate-skelton() {
echo "#!/usr/bin/env -S ${PROGNAME} -c '${CMD[*]}'"
echo "---"
aws "${CMD[@]}" --generate-cli-skeleton yaml-input
echo "..."
}
if [[ -n "${GEN:-}" ]]; then
if [[ -n "$FILE" ]]; then
generate-skelton >"$FILE"
chmod +x "$FILE"
else
generate-skelton
fi
else
if [[ -n "${FILE:-}" ]]; then
aws "${CMD[@]}" --cli-input-yaml "file://$FILE"
else
echo "${PROGNAME}: FILE is not specified" >&2
exit 1
fi
fi
@Hogeyama

Copy link
Copy Markdown
Author

Usage:

$ awc-cli-input-yaml -c 'sqs send-messge' --gen foo.yml
$ vim foo.yml
$ ./foo.yml

@Hogeyama

Copy link
Copy Markdown
Author

The contents of foo.yml after executing awc-cli-input-yaml -c 'sqs send-messge' --gen foo.yml

#!/usr/bin/env aws-cli-input-yaml -c 'sqs send-message'
---
QueueUrl: ''  # [REQUIRED] The URL of the Amazon SQS queue to which a message is sent.
MessageBody: '' # [REQUIRED] The message to send.
DelaySeconds: 0 #  The length of time, in seconds, for which to delay a specific message.
MessageAttributes: # Each message attribute consists of a Name, Type, and Value.
  KeyName:
    StringValue: ''  # Strings are Unicode with UTF-8 binary encoding.
    BinaryValue: !!binary '' # Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.
    StringListValues: # Not implemented.
    - ''
    BinaryListValues: # Not implemented.
    - !!binary ''
    DataType: '' # [REQUIRED] Amazon SQS supports the following logical data types.
MessageSystemAttributes: # The message system attribute to send.
  KeyName:
    StringValue: ''  # Strings are Unicode with UTF-8 binary encoding.
    BinaryValue: !!binary '' # Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.
    StringListValues: # Not implemented.
    - ''
    BinaryListValues: # Not implemented.
    - !!binary ''
    DataType: '' # [REQUIRED] Amazon SQS supports the following logical data types.
MessageDeduplicationId: '' # This parameter applies only to FIFO (first-in-first-out) queues.
MessageGroupId: '' # This parameter applies only to FIFO (first-in-first-out) queues.
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment