Skip to content

Instantly share code, notes, and snippets.

Avatar

Mims mims92

  • Liege
View GitHub Profile
@mims92
mims92 / pre-sign.py
Created Nov 2, 2020
AWS - Python - Pre Sign S3 key
View pre-sign.py
import boto3
from botocore.client import Config
session = boto3.Session(profile_name="",region_name="eu-central-1")
s3 = session.client('s3',region_name="eu-central-1",config=Config(signature_version='s3v4'))
s3_object="s3://..."
s3_bucket=s3_object.split("/")[2]
s3_key="/".join(s3_object.split("/")[3:])
print (" Generating pre-signed url...")
print(s3.generate_presigned_url('get_object', Params={'Bucket':s3_bucket,'Key':s3_key}, ExpiresIn=604800)) # 7days
@mims92
mims92 / awsgetparams
Created Sep 18, 2020
AWS - Bash - Get SSM parameters by path, (un)encrypted
View awsgetparams
#!/bin/bash
#chmod +x /usr/bin/awsgetparams
#Usage: awsgetparam <path> <profile name> <EMTPY|Y|y>
#Output: list of param value
PARAM_PATH="$1"
shift
PROFILE="$1"
shift
@mims92
mims92 / awsgetparam
Created Aug 24, 2020
AWS - Bash - Get a single SSM parameter, (un)encrypted
View awsgetparam
#!/bin/bash
#chmod +x /usr/bin/awsgetparam
#Usage: awsgetparam <param-name> <profile name> <EMTPY|Y|y>
#Output: param value
PARAM_NAME="$1"
shift
PROFILE="$1"
shift
@mims92
mims92 / awsecs
Created Jul 27, 2020
AWS - Bash - Get tasks instances
View awsecs
#!/bin/bash
#chmod +x /usr/bin/awsecs
#Usage: awsecs <service-name> <profile name>
#Output: list of ec2 instance id
SERVICE="$1"
shift
PROFILE="$1"
shift
@mims92
mims92 / awsssm
Created Jan 3, 2020
AWS - Bash - Start session using SSM Session manager
View awsssm
#!/bin/bash
#chmod +x /usr/bin/awsssm
#Usage: awsssm <instance id> <profile name>
aws ssm start-session --target $1 --profile $2
@mims92
mims92 / awsec2
Last active Jan 30, 2020
AWS - Bash - List all EC2 instances
View awsec2
#!/bin/bash
#chmod +x /usr/bin/awsec2
#Usage: awsec2 <profile-name>
aws ec2 describe-instances --profile $1 | jq -r '.[][].Instances[] | [ .InstanceId, (.Tags[]|select(.Key=="Name")|.Value), (.NetworkInterfaces[].PrivateIpAddresses[].PrivateIpAddress)] | select (.!=null) | @tsv' | column -s$'\t' -t'
@mims92
mims92 / awsaccounts
Created Jan 3, 2020
AWS - Bash - List all accounts id and name of the organization
View awsaccounts
#!/bin/bash
#chmod +x /usr/bin/awsaccounts
#Usage: awsaccounts
aws organizations list-accounts --profile <profile name> | jq -r -e '["ID","", "NAME"], (.Accounts[] | [.Id, .Name] ) | @tsv'
@mims92
mims92 / aws-ec2.sh
Created Nov 18, 2019
AWS - Bash - List Instances
View aws-ec2.sh
#!/bin/bash
#Usage: aws-ec2 <profile name>
aws ec2 describe-instances --profile $1 \
| jq -r '.[][].Instances[] | [ .InstanceId, (.Tags[]|select(.Key=="Name")|.Value), (.NetworkInterfaces[].PrivateIpAddresses[].PrivateIpAddress)]'
@mims92
mims92 / aws
Last active Jan 4, 2019
Linux - AWSCLI - aws cli with python3.6
View aws
# Requirement
# - https://gist.github.com/mims92/83b911783c2a23377c3f7dc9d1fe38b9
#--------
# Installation
# - Create the exectuable file under your PATH
#--------
# Files are being mounted in /app inside the container
#!/bin/bash
@mims92
mims92 / Dockerfile
Last active Mar 25, 2020
Linux - Docker - python & aws cli
View Dockerfile
# Requirements
# - Docker
#--------
# Installation
# - docker build -t <your image name> .
#--------
# "root" folder is app
FROM python:3.6-alpine
RUN pip3 install -U awscli
You can’t perform that action at this time.