Skip to content

Instantly share code, notes, and snippets.

View sebsto's full-sized avatar

Sébastien Stormacq sebsto

View GitHub Profile
@sebsto
sebsto / delete_amplify.sh
Created April 28, 2020 13:24
Delete Amlify Console App after `amplify delete`
APP_ID=$(aws amplify list-apps --query 'apps[? ! contains(keys(@), `productionBranch`) == `true`].[appId]' --output text )
echo $APP_ID | while read appid
do
aws amplify delete-app --app-id $appid
done
aws ec2 get-console-screenshot --instance-id ID --query "ImageData" --output text > f; cat f | base64 -D > screen.jpg
@sebsto
sebsto / gist:9a958ff1c761b8c7c90d
Last active December 16, 2019 17:51
Create IAM User and Attach a Policy using Boto and JSON
import json, boto
# Connect to IAM with boto
iam = boto.connect_iam(ACCESS_KEY, SECRET_KEY)
# Create user
user_response = iam.create_user('aws-user')
# Create Policy
policy = { 'Version' : '2012-10-17'}
@sebsto
sebsto / purge.sh
Created November 21, 2019 09:41
Delete Log groups
for NAME in $(aws logs describe-log-groups | jq -r .logGroups[].logGroupName | grep amplifynotes)
do
aws logs delete-log-group --log-group-name $NAME
done
@sebsto
sebsto / s3-ls.py
Created November 15, 2019 14:36
Amazon S3 - List all your buckets (aka 'ls' command)
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
@sebsto
sebsto / batch-write-items.json
Created October 5, 2019 13:05
Amazon DynamoDB batch write
{
"demo-global-table": [
{
"PutRequest": {
"Item": {
"id": {"S": "0123456789"},
"firstname": {"S": "Jeff"},
"lastname": {"S": "Barr"}
}
}
@sebsto
sebsto / S3.py
Created May 4, 2019 12:35
Bien démarrer avec Amazon S3 et Python
import logging
import boto3
from botocore.exceptions import ClientError
def upload_file(file_name, bucket, object_name=None):
"""Upload a file to an S3 bucket
:param file_name: File to upload
:param bucket: Bucket to upload to
:param object_name: S3 object name. If not specified then file_name is used
@sebsto
sebsto / gist:20e550876db521710186
Created February 12, 2015 16:38
Block users access to AWS EC2 meta data
sudo iptables -A OUTPUT -m owner ! --uid-owner root -d 169.254.169.254 -j DROP
@sebsto
sebsto / async4.js
Created June 25, 2019 09:07
Async - AWS SDK for Javascript
function updatePlayCount(your_object) {
return new Promise((resolve, reject) => {
const LAST_PLAYED_TIME = Math.round(new Date() / 1000);
var params = {
TableName: "your_table",
Key: {
"cognitoid": your_object.userId,
@sebsto
sebsto / async3.js
Created June 25, 2019 08:57
Async - the good
async function asyncWorker() {
return new Promise( (resolve, reject) => {
setTimeout(resolve, 2000);
});
}
async function main() {
console.debug('Started');