aws-cloudformationaccess-keys

Declaring an IAM Access Key Resource by CloudFormation


I created a user in my template with an access key:

"MyAccessKey" : {
   "Type" : "AWS::IAM::AccessKey",
   "Properties" : {
      "UserName" : { "Ref" : "User12" }
   }
} 

I need to get the access key ID and the secret key in the output of the template. How to do that ? Thank you


Solution

  • The access key id and the secret key are available as return values for the AWS::IAM::AccessKey resource:

    "Outputs" : {
      "MyAccessKeyId": {
        "Ref" : "MyAccessKey"
      },
      "MySecretKey": {
        "Fn::GetAtt": [ "MyAccessKey", "SecretAccessKey" ]
      }
    }