Showing posts with label AWS. Show all posts
Showing posts with label AWS. Show all posts

Friday, August 29, 2014

Configuring and Enabling Virutal MFA for AWS account

I tried enabling AWS MFA (Multi-Factor Authentication) for AWS root account, as it supports Virtual MFA applications such as Google Authenticator for iPhone or Android or Authenticator for Windows phone as for free and we can use AWS MFA itself without any charge as well.
This is a quick instruction to apply AWS MFA with Google Authenticator.

  1. Install Google Authenticator in your smartphone.
    Cf. Virtual MFA applications
  2. Enable virtual MFA application with the official instruction.

    * Sign in to the AWS Management Console and move to IAM section.
    * Click Manage MFA.

    * Select "A Virtual MFA device" and click "Next Step".


    * Just click "Next Step".


    * Scan the QR code on the screen by Google Authenticator and confirm the two codes and enter them.


    * Click "Finish" after successfully associating the MFA device.

  3. Confirm that the AWS root account is available with Google Authenticator.

    * Sign in to the AWS management console with your AWS root account.

    * Confirm the authentication code with Google Authenticator and enter the code.

  4. Delete your AWS account root access key.
    Security status, "Delete your root access keys" will be green after deleting it.

I checked the cloud providers that support Multi-Factor Authentication, but not so many providers support it?

Thursday, August 7, 2014

Failed Access Denied: S3 properties on us-east-1 region

When I created s3 buckets at each regions including us-east-1, us-west1, us-west-2, and ap-northeast-1 and applied the IAM policies below to a IAM group. I got some of the properties of other than us-east-1 region somehow.
I created an IAM group and attached two IAM policies with the group.
  • IAM policy to define the buckets to operate and access source IP address.
{ "Statement": [ { "Condition": { "IpAddress": { "aws:SourceIp": [ "xxx.xxx.xxx.xxx/32", "xxx.xxx.xxx.xxx/32" ] } }, "Resource": [ "arn:aws:s3:::bucket_name.ap-northeast-1", "arn:aws:s3:::bucket_name.ap-northeast-1/*", "arn:aws:s3:::bucket_name.us-west-1", "arn:aws:s3:::bucket_name.us-west-1/*", "arn:aws:s3:::bucket_name.us-west-1", "arn:aws:s3:::bucket_name.us-west-1/*", "arn:aws:s3:::bucket_name.us-west-2", "arn:aws:s3:::bucket_name.us-west-2/*" ], "Action": "s3:*", "Effect": "Allow" } ], "Version": "2012-10-17" }
  • IAM policy to list all the buckets for a s3 tool like S3 Browser
{
  "Statement": [
    {
      "Resource": "*",
      "Action": "s3:List*",
      "Effect": "Allow"
    }
  ],
  "Version": "2012-10-17"
}
I got the properties of us-west-1, us-west-2, ap-northeast-1, but couldn't get those of us-east-1, though the same IAM policies are applied.


I successfully got the properties of us-east-1 after adding the action as follows.



{
  "Statement": [
    {
      "Resource": "*",
      "Action": [
        "s3:List*",
        "s3:Get*"
      ],
      "Effect": "Allow"
    }
  ],
  "Version": "2012-10-17"
}

I am wondering if us-east-1 (US standard) region is different from other regions in how to apply IAM policy because it is the 1st region of AWS???

Friday, July 25, 2014

AWS CLI memorandum - Describe all Availability Zones for each region

I was creating CloudFormation template and wanted to list all of the Availability Zones for each regions to create the following Mappings in the template.

  "Mappings": {
    "AvailabilityZoneMap": {
       "ap-northeast-1": { "AZa": "ap-northeast-1a", "AZb": "ap-northeast-1b", "AZc": "ap-northeast-1c" }
      ...
       "ap-northeast-2": { "AZa": "ap-northeast-2a", "AZb": "ap-northeast-2b", "AZc": "ap-northeast-2c" 
    }
  },

Describing all the names of the regions
aws ec2 describe-regions | jq -r '.Regions[].RegionName'
eu-west-1
sa-east-1
us-east-1
ap-northeast-1
us-west-2
us-west-1
ap-southeast-1
ap-southeast-2

Describing all the AZs for each regions
$ for i in `aws ec2 describe-regions | jq -r '.Regions[].RegionName'` ; do
ec2-describe-availability-zones --region $i
done

AVAILABILITYZONE        eu-west-1a      available       eu-west-1       
AVAILABILITYZONE        eu-west-1b      available       eu-west-1       
AVAILABILITYZONE        eu-west-1c      available       eu-west-1       
AVAILABILITYZONE        sa-east-1a      available       sa-east-1       
AVAILABILITYZONE        sa-east-1b      available       sa-east-1       
AVAILABILITYZONE        us-east-1a      available       us-east-1       
AVAILABILITYZONE        us-east-1b      available       us-east-1       
AVAILABILITYZONE        us-east-1c      available       us-east-1       
AVAILABILITYZONE        ap-northeast-1a available       ap-northeast-1  
AVAILABILITYZONE        ap-northeast-1c available       ap-northeast-1  
AVAILABILITYZONE        us-west-2a      available       us-west-2       
AVAILABILITYZONE        us-west-2b      available       us-west-2       
AVAILABILITYZONE        us-west-2c      available       us-west-2       
AVAILABILITYZONE        us-west-1a      available       us-west-1       
AVAILABILITYZONE        us-west-1c      available       us-west-1       
AVAILABILITYZONE        ap-southeast-1a available       ap-southeast-1  
AVAILABILITYZONE        ap-southeast-1b available       ap-southeast-1  
AVAILABILITYZONE        ap-southeast-2a available       ap-southeast-2  
AVAILABILITYZONE        ap-southeast-2b available       ap-southeast-2  

I tried using AWS CLI to do the same, but AWS CLI only includes the zones for the region that you're currently using and it does not show the AZs for the other regions.
Describes one or more of the Availability Zones that are available to you. The results include zones only for the region you're currently using. If there is an event impacting an Availability Zone, you can use this request to view the state and any provided message for that Availability Zone.

$ for i in `aws ec2 describe-regions | jq -r '.Regions[].RegionName'` ; do
aws ec2 describe-availability-zones --zone-names $i
done
A client error (InvalidParameterValue) occurred: Invalid availability zone: [eu-west-1]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [sa-east-1]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [us-east-1]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [ap-northeast-1]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [us-west-2]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [us-west-1]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [ap-southeast-1]
A client error (InvalidParameterValue) occurred: Invalid availability zone: [ap-southeast-2]

I need to think about how to convert the results into JSON format next.


Wednesday, June 11, 2014

AWS CLI memorandum - Delete S3 Buckets and all of the objects simultaneously

When we put some objects into S3 bucket to verify or validate a CloudFormation stack by uploading a template to S3 bucket, the buckets store thousands of objects that I don't have to keep anymore and we sometimes have to pay too much cost for that after receiving the billing.

Why don't we delete all of the objects and buckets simultaneously or you should consider of using Object Lifecycle Management in advance to automatically delete the objects that has been expired.

* List the buckets you want to remove and input them into a file
* Recursively delete all of the objects, the buckets and confirm that they are deleted
* Use --quiet option if you want to quietly remove

That's it!

Wednesday, April 2, 2014

AWS CLI memorandum - Describe the maximum and minumum price from the spot price history

I begin to use Amazon EC2 Spot Instances and feel like knowing the maximum and minimum price from the spot price history with a combination of AWS CLI and jq.
The sample below is supposed that Instance type is m1.small and Availability Zone is ap-northeast-1a in Tokyo region.

* Describe the maximum price

* Describe the minimum price
I tried, but I am not sure if it's possible to output both maximum and minimum in one line.



Tuesday, March 25, 2014

Monitoring tool for hyblid cloud and automating - installing Hyclops for Zabbix (updated)

I used to write about how to install zabbix+hyclops to automatically register zabbix hosts on AWS EC2 instance before. Recently, I tried installing the latest version of zabbix-2.2.2 and hyclops-0.2.
In fact, it's not working as expected so far because it seems that hyclops.connector.ec2 (ec2.py) python script is not working correctly. I will update this article when finishing to fix the problem (asking the engineers who created hyclops to debug the issue currently).
After uninstalling apache-libcloud from 0.14.1 to 0.13.2, the issue has been resolved.
Ikeda-san, thanks for your quick feedback and support!

OS, Middle ware, Libraries
  • AMI ID (AWS EC2 Instance): ami-31e86030
  • OS: CentOS 6.5(x86_64)
  • Kernel: 2.6.32-358.6.1.el6.x86_64
  • Apache: 2.2.15
  • MySQL: 5.6.16
  • PHP: 5.3.3
  • Zabbix: 2.2.2
  • Hyclops: 0.2.0
  • ZeroMQ: 3.2.2
  • GateOne: 1.1.1
  • Python: 2.7.5
  • Python Modules
    • apache-libcloud (0.14.1) (0.13.2)
    • boto (2.27.0)
    • configobj (5.0.2)
    • distribute (0.6.35)
    • hyclops (0.2.1)
    • ipython (1.2.1)
    • lockfile (0.9.1)
    • pip (1.5.4)
    • psphere (0.5.2)
    • python-daemon (1.6)
    • PyYAML (3.10)
    • pyzmq (14.1.1)
    • setuptools (0.6c11)
    • six (1.5.2)
    • suds (0.4)
    • tornado (2.4.1)
    • wsgiref (0.1.2)
    • zabbix-api (1.0)

Upgrade to CentOS-6.5 from 6.4
MySQL-5.6

Apache-2.2
PHP-5.3
Libraries for Zabbix
Zabbix 2.2
ZeroMQ
Createing Zabbix schema
Python-2.7, Python packages
Python modules
Python module (apache-libcloud)
Make sure that apache-libcloud-0.13.2 should be compiled and installed from tar ball because it failed to install apache-libcloud-0.13.2 with python-2.7 via pip.
Gateone
Replacing some Zabbix dashboard files
I changed the python script for get_aws_charges.py and push_message.py scripts are changed.
Importing Zabbix templates,scripts and globalmacro data
After creating value mappings and creating zabbix hosts on zaxbbix dashboard, I got the error message below in fact. I need to dive into the logging...
This issue has been solved by downgrading apache-libcloud from 0.14.1 to 0.13.2.
See zabbix_server.log to confirm the both python scripts are working to get aws charges and push messages.
See hyclops_server.log to confirm that polling and creating zabbix hosts have been successful.
* You need to change "log_level = DEBUG" on /opt/hyclops/hyclops.conf to debug.

iJAWS@Doorkeeper