Skip to content

Instantly share code, notes, and snippets.

@amui
amui / gist:78ad569deec7849846eedf6b4a20bf40
Last active January 22, 2025 23:04
Get creds for current assumed role using boto3
python3 -c "import boto3; creds = boto3.Session().get_credentials().get_frozen_credentials(); print(f'AWS_ACCESS_KEY_ID={creds.access_key}\nAWS_SECRET_ACCESS_KEY={creds.secret_key}\nAWS_SESSION_TOKEN={creds.token}')"
@amui
amui / resource_v_client.py
Last active May 12, 2023 17:18
Comparing boto3 resource vs client
# Boto3 examples showing difference between client and resource
#
import boto3
from boto3.dynamodb.conditions import Key
from botocore.config import Config
from pprint import pprint
my_config = Config(
region_name = 'us-east-1'
@amui
amui / s3clientsample.js
Created October 26, 2021 06:38
S3 Client JS v3 w/ Cognito User Pool auth and getObject (V2 style)
// variable 'user' stores the social oauth response through Cognito User Pool
const client = new S3({
region: "<REGION>",
credentials: fromCognitoIdentityPool({
identityPoolId: "<IDENTITY POOL ID>",
logins: {
"cognito-idp.<REGION>.amazonaws.com/<USER POOL ID>": user.signInUserSession.idToken.jwtToken,
},
clientConfig: { region: "<REGION>" },
@amui
amui / commands.sh
Last active January 10, 2018 16:36
AWS CLI
#!/bin/bash
# list running instances
aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,Placement.AvailabilityZone,Tags[].Value]' --filters "Name=instance-state-name,Values=running" --region us-east-2
@amui
amui / maxage_multipart.py
Created April 10, 2015 00:50
Set cache-control max-age for S3 objects larger than 5GB
from boto.s3.connection import S3Connection
# cache-control metadata
meta = {'Cache-Control':'max-age=43200'}
connection = S3Connection(KEY, SECRET)
bucket = connection.get_bucket('mui.test.bucket')
key = bucket.lookup('sourcefile.tar')
chunk = 99999999
@amui
amui / maxage.py
Created April 1, 2015 19:37
Set cache-control max-age for objects in S3 bucket
from boto.s3.connection import S3Connection
# make sure api creds set, KEY/SECRET are just placeholders
connection = S3Connection(KEY, SECRET)
bucket = connection.get_bucket("just.a.test.bucket.really")
keys = bucket.get_all_keys()
for key in keys:
key.set_metadata('Cache-Control','max-age=43200')
key.copy(
@amui
amui / elb.config
Last active April 1, 2022 18:58
ELB Healthcheck configuration for .ebextensions
Resources:
AWSEBLoadBalancer:
Type: "AWS::ElasticLoadBalancing::LoadBalancer"
Properties:
HealthCheck:
Target: "HTTP:80/health.html"