Skip to content

Instantly share code, notes, and snippets.

View ianmas-aws's full-sized avatar

Ian Massingham ianmas-aws

  • Amazon Web Services
  • UK
View GitHub Profile
@ianmas-aws
ianmas-aws / gist:8840850
Last active August 29, 2015 13:56
How use the command line to find out which tags are associated with an EC2 instance
Try this - it requires that you have the AWS command line tools installed and that your instance has either been assigned an IAM role with sufficent permissions, or that your AWS command line tools have been set up with the right credentials. You should use IAM roles if you want to get this info at first boot, which I suspect is what you want to use this for?
aws ec2 describe-instances --region eu-west-1 --output text --instance-ids `curl -s http://169.254.169.254/latest/meta-data/instance-id` | grep TAGS
If you create an IAM role called AllowDescribeInstances with the following policy this and assign it to your instances, this is the minimum permissions set that is required.
{
"Version": "2012-10-17",
"Statement": [
@ianmas-aws
ianmas-aws / mongoDBWriter_lambda.py
Created March 28, 2017 07:43
Example Lambda Fuction for pushing event data into a MongoDB database
# Run this Lambda function inside a VPC with a MongoDB instance inside it.
# Set up security groups to allow the function to communicate with the MongoDB endpoint
# NAT service or NAT instance is required because the function need to access AWS KMS, which an external endpoint
# Set four environment variables for the function containing the details required for the MongoDB endpoint uri
# I used the Bitnami MongoDB install from the AWS Marketplace
import boto3
import os
from base64 import b64decode
from requests_oauthlib import OAuth1Session
import os
CONSUMER_KEY = os.getenv("CONSUMER_KEY")
CONSUMER_SECRET = os.getenv("CONSUMER_SECRET")
ACCESS_KEY = os.getenv("ACCESS_KEY")
ACCESS_SECRET = os.getenv("ACCESS_SECRET")
twitter = OAuth1Session(
CONSUMER_KEY,
client_secret=CONSUMER_SECRET,
{
"executionRoleArn": "arn:aws:iam::<<ACCOUNT_NUMBER>>:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/es-proxy",
"awslogs-region": "us-east-1",