Skip to content

Instantly share code, notes, and snippets.

View mda590's full-sized avatar
☁️
Feeling cloudy

Matt Adorjan mda590

☁️
Feeling cloudy
View GitHub Profile
@mda590
mda590 / boto3_listinstances_example.py
Last active May 29, 2024 09:08
Example using boto3 to list running EC2 instances
import boto3
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
# create filter for instances in running state
filters = [
{
'Name': 'instance-state-name',
'Values': ['running']
@mda590
mda590 / boto3_get-ssm-parameter.py
Last active July 7, 2022 12:23
Get a Secure String parameter stored in the EC2 Systems Manager
def getParameter(param_name):
"""
This function reads a secure parameter from AWS' SSM service.
The request must be passed a valid parameter name, as well as
temporary credentials which can be used to access the parameter.
The parameter's value is returned.
"""
# Create the SSM Client
@mda590
mda590 / ec2-schedule-example.py
Created February 7, 2017 19:39
Example EC2 Scheduler Script based on a tag value
import boto3
from datetime import datetime, timedelta
def lambda_handler(event, context):
try:
# Create connection to the EC2 using Boto3 resources interface
ec2 = boto3.resource('ec2', region_name='us-east-1')
# Get the current time
timeOffset = datetime.utcnow() + timedelta(hours=defaultTimeZone)
@mda590
mda590 / gist:9404128f5157f38098189616a56070f6
Created March 20, 2017 22:33
Install Docker on RHEL AWS
sudo yum-config-manager --enable "Red Hat Enterprise Linux Server 7 Extra(RPMs)"
sudo yum install docker -y
@mda590
mda590 / ssm-secrets-01.sh
Created March 22, 2017 12:38
Create Secure String in EC2 Parameter Store
aws --region=us-east-2 ssm put-parameter --name "<string-name>" --value '<secure data>' --type SecureString --key-id alias/<kms-key-name>
@mda590
mda590 / ssm-secrets-02.sh
Created March 22, 2017 12:39
Create Secure String in EC2 Parameter Store - Example
aws --region=us-east-2 ssm put-parameter --name "secret-password" --value 'password1234' --type SecureString --key-id alias/secret-strings
@mda590
mda590 / ssm-secrets-03.sh
Created March 22, 2017 12:40
Create Secure String in EC2 Parameter Store - Example Value
{ "AccessKey": "ABCDE43235132D", "SecretKey": "ACBDEFGHIJKL123456789ABCDEF" }
@mda590
mda590 / ssm-secrets-04.sh
Created March 22, 2017 12:41
Get Secure String from EC2 Parameter Store
aws --region=us-east-2 ssm get-parameters --names "<string-name>" --with-decryption
@mda590
mda590 / ssm-secrets-05.sh
Created March 22, 2017 12:42
Get Secure String from EC2 Parameter Store - Example
aws --region=us-east-2 ssm get-parameters --names "secret-password" --with-decryption
@mda590
mda590 / listAllS3BucketsObjects.py
Created April 27, 2017 17:23
List all S3 Buckets and Objects
#
# Print all S3 buckets and objects
# Warning: If you have a lot of S3 objects, this could potentially incur a large cost.
#
import boto3
client = boto3.client('s3')
buckets = client.list_buckets()