Wednesday, August 31, 2016

AWS IAM Policy Statement to Register and Deregister Instances with/from ELB

E.g.

{
   "Version": "2012-10-17",
   "Statement": [
       {
           "Sid": "Stmtxxxxxxxxx",
           "Effect": "Allow",
           "Action": [
               "elasticloadbalancing:RegisterInstancesWithLoadBalancer",
               "elasticloadbalancing:DeregisterInstancesFromLoadBalancer"
           ],
           "Resource": [
               "arn:aws:elasticloadbalancing:aws-region:aws-account-id:loadbalancer/*"
           ]
       }
   ]
}

AWS IAM Permissions to Create Tags

Had a hard time getting this to work, and it turns out that only permissions to the "ec2:CreateTags" action is needed, however, the moment the resource is constrained (even to all resources within a specific region), I was unable to tag an EC2 instance. I was only able to tag an EC2 instance when the "Resource" was set to *

{
   "Version": "2012-10-17",
   "Statement": [
       {
           "Sid": "Stmtxxxxxxxx",
           "Effect": "Allow",
           "Action": [
               "ec2:CreateTags"
           ],
           "Resource": [
               "*"
           ]
       }
   ]
}

Monday, August 29, 2016

AWS CloudWatch Logs: Create Log Stream via Command Line


aws logs create-log-stream --log-group-name groupName --log-stream-name streamName

Ansible: Running a Command on the Local Machine

To run an command on the shell of Ansible machine (i.e. instead of the target machine), use the local_action module:

local_action: command xxxxxxxxx

Ansible: EC2 Instance ID Variable


{{ ansible_ec2_instance_id }}

MongoDB: Query for Documents Based On Array Size


db.collectionName.count({"arrayName":{$exists:true},$where:'this.arrayName.length>3'})

Reference: http://stackoverflow.com/questions/7811163/query-for-documents-where-array-size-is-greater-than-1

Tuesday, August 9, 2016

Ant Java Compilation Classpath

If there are many jar files in the classpath, instead of specifying all of them, include all jar files in a folder this way: http://stackoverflow.com/questions/6103516/ant-adding-multiple-jars-in-classpath-dynamically

Amazon Linux Install Ansible

The YUM method won't work, due to differing python versions.

Use pip instead.
sudo pip install ansible