Skip to content

Instantly share code, notes, and snippets.

View rdp-cloud's full-sized avatar
💭
I may be slow to respond.

rdp-cloud

💭
I may be slow to respond.
View GitHub Profile
@rdp-cloud
rdp-cloud / gist:16a4330282c251e6cace08f6a49a5135
Created October 19, 2017 22:50
Example AWS IAM Security Policy to enforce tag usage during deployment
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:RunInstances"
            ],
            "Resource": [
                "*"
@rdp-cloud
rdp-cloud / awscli-currentAmzLinux.sh
Created March 31, 2017 22:01
When run from an EC2 instance this snippet will return the CURRENT ami id for Amazon Linux in the REGION that the instance is running in and load it up into a variable called currentAMI.
#!/bin/bash -xe
# grab the Availability Zone from the Meta Data service
az=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone/)
# drop the trailing zone to get the REGION the instance is running in.
currentRegion=${az%?}
# retirve the source AMI (latest Amazon Linux image in this case)
currentAMI=$(aws ec2 describe-images --owners self amazon --filters "Name=name,Values=amzn-ami-hvm-*gp2" --query 'Images[].[CreationDate,ImageId]' --output text --region $currentRegion | sort -k1 | tail -n1 | awk '{print $2}')