Skip to content

Instantly share code, notes, and snippets.

View mtp1376's full-sized avatar

Mohammad Teimori Pabandi mtp1376

  • Istanbul, Türkiye
  • 16:04 (UTC +03:00)
View GitHub Profile
@mtp1376
mtp1376 / cache-proof.js
Created March 2, 2023 11:38
This script proves that AWS SQS APIs have a cache that caches the result based on the exact input for 40 seconds
import { SQS } from '@aws-sdk/client-sqs';
import { now } from "lodash";
const sqsClient = new SQS({
credentials: {
accessKeyId: 'X',
secretAccessKey: 'Y',
},
region: 'us-east-2'
});
# Replace "ARN_FOR_MFA_HERE" with your MFA device ARN
# Put the keys you get from AWS IAM console in the "iam-user" profile
# Run the script: "bash new-aws-session-token.sh 123456" (replace 123456 with the code you get from the Authenticator app)
set -e
aws sts get-session-token --serial-number ARN_FOR_MFA_HERE --token-code $1 --profile iam-user > /tmp/aws.json
ACCESS_KEY_ID=`jq -r '.Credentials.AccessKeyId' /tmp/aws.json`
SECRET_ACCESS_KEY=`jq -r '.Credentials.SecretAccessKey' /tmp/aws.json`
SESSION_TOKEN=`jq -r '.Credentials.SessionToken' /tmp/aws.json`
aws configure set --profile default aws_access_key_id "$ACCESS_KEY_ID"
aws configure set --profile default aws_secret_access_key "$SECRET_ACCESS_KEY"