Skip to content

Instantly share code, notes, and snippets.

View libert-xyz's full-sized avatar
🗽
/dev/urandom

Libert Schmidt libert-xyz

🗽
/dev/urandom
View GitHub Profile
@libert-xyz
libert-xyz / ebs_resize.sh
Last active June 26, 2020 16:18
Resize EBS storage from the EC2 itself (Amazon Linux AMI release 2018.03)
#!/bin/bash
# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Install the jq command-line JSON processor.
sudo yum -y install jq
# Get the ID of the envrionment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data//instance-id)
@cgoering
cgoering / template.yaml
Created April 26, 2019 18:28
AWS Lambda memory usage metric in CloudFormation
CustomMetric:
Type: AWS::Logs::MetricFilter
Properties:
LogGroupName: !Sub /aws/lambda/${AWS::StackName}
FilterPattern: '[str="REPORT", ..., str="Max", str="Memory", str="Used:", MaxMemoryUsed, str="MB"]'
MetricTransformations:
- MetricNamespace: Organization/Project/Service
MetricName: MaxMemoryUsed
MetricValue: $MaxMemoryUsed
@Slakah
Slakah / ssm-to-env.sh
Created May 14, 2018 10:20
Convert AWS SSM parameters to environment variables, used as `eval $(./ssm-to-env.sh "<ssm-path>")`
#!/bin/bash
set -uxe
# Reads the ssm path and echos out the parameters in the form
# export NAME=some-value
readonly path=$1
exec aws --region us-east-1 ssm get-parameters-by-path --no-paginate --path $path --with-decryption --query Parameters | \
jq -r 'map("\(.Name | sub("'$path'";""))=\(.Value)") | join("\n")' | \
@ozgurakan
ozgurakan / lambda_assume_role.py
Last active January 12, 2023 08:55
Assume Role within A Lambda function (Python)
import boto3
# you can assign role in the function like below
# ROLE_ARN = 'arn:aws:iam::01234567890:role/my_role'
#
# or you can pass role as an evironment varibale
# ROLE_ARN = os.environ['role_arn']
ROLE_ARN = = os.environ['role_arn']
@nmarley
nmarley / dec.py
Last active August 8, 2023 13:55
AWS KMS encryption/decryption using Python/Boto3
import boto3
import base64
if __name__ == '__main__':
session = boto3.session.Session()
kms = session.client('kms')
encrypted_password = 'AQECAHjgTiiE7TYRGp5Irf8jQ3HzlaQaHGYgsUJDaavnHcFm0gAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDDwxVQuG0oVwpkU7nQIBEIAoVGk1/wpserb+GVUOzE7PiL/Nr9fTDFKZfpKpF0ip2ct4B2q0Wn6ZZw=='
binary_data = base64.b64decode(encrypted_password)
@libert-xyz
libert-xyz / dateAndtime.py
Created November 26, 2016 15:22
Date and Time manipulation in python
import datetime
import pytz
tday = datetime.date.today()
bday = datime.date(2017,8,17)
#Example1
#Time until my bday
till_bday = bday - tday #timedelta object
print(till_bday)
@JohnPreston
JohnPreston / encrypt_password_to_dyndb.py
Last active November 18, 2023 08:29
Generates, encrypt and store password in DynamoDB
import base64
import uuid
import httplib
import urlparse
import json
import boto3
import string
import random
@simon-weber
simon-weber / disable_troublesom_scaling_processes.py
Created August 26, 2016 19:28
disable ASG scaling processes during CodeDeploy deploys
"""
Suspend an auto scaling group's scaling processes that can interfere with CodeDeploy deploys.
It assumes a single ASG per deployment group.
To use this:
* create a lambda function with this code, then hook up it up to an SNS topic that receives all deployment events (but not host events).
* attach that topic as a trigger in your deployment groups.
Unlike AWS's in-appspec approach, this supports arbitrary deploy concurrency.

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
@vancluever
vancluever / amifind.sh
Created January 26, 2016 08:05
Find the most recent Ubuntu AMI using aws-cli (or any other AMI for that matter)
#!/bin/sh
# Use AWS CLI to get the most recent version of an AMI that
# matches certain criteria. Has obvious uses. Made possible via
# --query, --output text, and the fact that RFC3339 datetime
# fields are easily sortable.
export AWS_DEFAULT_REGION=us-east-1
aws ec2 describe-images \