Skip to content

Instantly share code, notes, and snippets.

@ronny
Created November 29, 2016 01:59
Show Gist options
  • Save ronny/fc533dc76d77be42ea67fea95bb32b03 to your computer and use it in GitHub Desktop.
Save ronny/fc533dc76d77be42ea67fea95bb32b03 to your computer and use it in GitHub Desktop.
#!/bin/bash
jq --version | grep "^jq-" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Make sure 'jq' is installed. e.g. 'brew install jq'"
exit 1
fi
aws --version 2>&1 | grep "^aws-cli" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Make sure 'awscli' is installed. e.g. 'pip install awscli'"
exit 1
fi
if [ -z "${1}" -o -z "${2}" ]; then
echo "Usage: ${0} <kinesis-stream-name> <identity-pool-id> [identity-id]"
exit 1
fi
# TODO: parameterise these
cognito_region="ap-northeast-1"
kinesis_region="ap-southeast-1"
kinesis_stream_name="${1}"
identity_pool_id="${2}"
if [ -z "${3}" ]; then
echo "Identity ID not given, requesting a new one from the pool..."
identity_id=$(aws cognito-identity get-id --identity-pool-id "${identity_pool_id}" --region "${cognito_region}" | jq -r .IdentityId)
else
identity_id="${3}"
fi
echo "Identity ID: ${identity_id}"
creds=$(aws cognito-identity get-credentials-for-identity --identity-id "${identity_id}" --region "${cognito_region}")
export AWS_ACCESS_KEY_ID=$(echo "${creds}" | jq -r .Credentials.AccessKeyId)
export AWS_SECRET_ACCESS_KEY=$(echo "${creds}" | jq -r .Credentials.SecretKey)
export AWS_SESSION_TOKEN=$(echo "${creds}" | jq -r .Credentials.SessionToken)
env | grep AWS
set -x
aws kinesis put-record --stream-name "${kinesis_stream_name}" --partition-key lol --data foo --region "${kinesis_region}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment