Pages

Wednesday 29 January 2014

aws::cloudformation(AWS::IAM::AccessKey):::How to get access keys (access-key, secret-key)

Make use of  "AWS::IAM::AccessKey" resource type to get credentials and use throughout anywhere in the cloudformation script.
Depends on
  AWS::IAM::User   : for its userName value.

Syntax
{
   "Type": "AWS::IAM::AccessKey",
   "Properties": {
      "Serial": Integer,
      "Status": String,
      "UserName": String
   }
}    


eg.
    "HostKeys" : {
      "Type" : "AWS::IAM::AccessKey",
      "Properties" : {
        "UserName" : { "Ref": "User" }
     }
    },

How to get UserName ? Ref: "User" ?
Use AWS::IAM::User
eg.
    "User" : {
      "Type" : "AWS::IAM::User",
      "Properties" : {
        "Path": "/",
        "Policies": [{
          "PolicyName": "root",
          "PolicyDocument": { "Statement":[{
            "Effect":"Allow",
            "Action":"*",
            "Resource":"*"
           }
          ]}
        }]
      }
    }



To get various string values do this:
  1. access-key:   {"Ref" : "HostKeys" }
  2. secret-key:   { "Fn::GetAtt" : [ "HostKeys", "SecretAccessKey" ]}


Extra: To get user logged in aws region:  { "Ref" :"AWS::Region" }
       

Reference: 

  1. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-iam-accesskey.html
  2. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-iam.html#scenario-iam-accesskey

1 comment:

  1. Very informative, thanks for providing useful information keep update with more information. Get touch with AWS Online Course Bangalore

    ReplyDelete