Skip to content

Instantly share code, notes, and snippets.

@krishnan-mani
Created January 29, 2018 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnan-mani/c9a064a3a40d5df42bedcc7bd9ae45b4 to your computer and use it in GitHub Desktop.
Save krishnan-mani/c9a064a3a40d5df42bedcc7bd9ae45b4 to your computer and use it in GitHub Desktop.
Put an item in DynamoDB with a one day TTL
#!/usr/bin/env bash
set -euxo pipefail
TABLE_NAME="$1"
REGION="$2"
NOW_IN_MINUTES=$(date +%Y%m%dT%H%M%z)
EPOCH_TIME=$(date +%s)
ONE_DAY_LATER=$(($EPOCH_TIME+86400))
item={\"id\":{\"S\":\"$NOW_IN_MINUTES\"},\"expireAt\":{\"N\":\"$ONE_DAY_LATER\"},\"hostname\":{\"S\":\"$(hostname)\"}}
echo $item > item.json
aws --region $REGION dynamodb put-item --table-name $TABLE_NAME --item file://item.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment