Logging AWS CloudFormation API calls with AWS CloudTrail
AWS CloudFormation is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in CloudFormation. CloudTrail captures all API calls for CloudFormation as events, including calls from the CloudFormation console and from code calls to the CloudFormation APIs. If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for CloudFormation. If you don't configure a trail, you can still view the most recent events in the CloudTrail console in Event history. Using the information collected by CloudTrail, you can determine the request that was made to CloudFormation, the IP address from which the request was made, who made the request, when it was made, and additional details.
To learn more about CloudTrail, see the AWS CloudTrail User Guide.
CloudFormation information in CloudTrail
CloudTrail is enabled on your AWS account when you create the account. When activity occurs in CloudFormation, that activity is recorded in a CloudTrail event along with other AWS service events in Event history. You can view, search, and download recent events in your AWS account. For more information, see Viewing events with CloudTrail event history.
For an ongoing record of events in your AWS account, including events for CloudFormation, create a trail. A trail enables CloudTrail to deliver log files to an Amazon S3 bucket. By default, when you create a trail in the console, the trail applies to all Regions. The trail logs events from all Regions in the AWS partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can configure other AWS services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see:
All CloudFormation actions are logged by CloudTrail and are documented in the AWS CloudFormation API Reference. For
example, calls to the CreateStack
, DeleteStack
, and
ListStacks
sections generate entries in the CloudTrail log files.
Every event or log entry contains information about who generated the request. The identity information helps you determine the following:
-
Whether the request was made with root or IAM user credentials.
-
Whether the request was made with temporary security credentials for a role or federated user.
-
Whether the request was made by another AWS service.
For more information, see the CloudTrail userIdentity element.
Understanding CloudFormation log file entries
A trail is a configuration that enables delivery of events as log files to an Amazon S3 bucket that you specify. CloudTrail log files contain one or more log entries. An event represents a single request from any source and includes information about the requested operation, the date and time of the operation, request parameters, and so on. CloudTrail log files aren't an ordered stack trace of the public API calls, so they don't appear in any specific order.
The following example shows a CloudTrail log entry that demonstrates the
CreateStack
operation. The operation was made by an IAM user named
Alice.
Note
Only the input parameter key names are logged. Parameter values aren't logged.
{ "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "AIDAABCDEFGHIJKLNMOPQ", "arn": "arn:aws:iam::012345678910:user/Alice", "accountId": "012345678910", "accessKeyId": "AKIDEXAMPLE", "userName": "Alice" }, "eventTime": "2014-03-24T21:02:43Z", "eventSource": "cloudformation.amazonaws.com", "eventName": "CreateStack", "awsRegion": "us-east-1", "sourceIPAddress": "127.0.0.1", "userAgent": "aws-cli/1.2.11 Python/2.7.4 Linux/2.6.18-164.el5", "requestParameters": { "templateURL": "
templateURL
", "tags": [ { "key": "test", "value": "tag" } ], "stackName": "my-test-stack", "disableRollback": true, "parameters": [ { "parameterKey": "password" }, { "parameterKey": "securitygroup" } ] }, "responseElements": { "stackId": "arn:aws:cloudformation:us-east-1:012345678910:stack/my-test-stack/a38e6a60-b397-11e3-b0fc-08002755629e" }, "requestID": "9f960720-b397-11e3-bb75-a5b75389b02d", "eventID": "9bf6cfb8-83e1-4589-9a70-b971e727099b" }
The following example shows that Alice called the UpdateStack
operation on
the my-test-stack
stack:
{ "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "AIDAABCDEFGHIJKLNMOPQ", "arn": "arn:aws:iam::012345678910:user/Alice", "accountId": "012345678910", "accessKeyId": "AKIDEXAMPLE", "userName": "Alice" }, "eventTime": "2014-03-24T21:04:29Z", "eventSource": "cloudformation.amazonaws.com", "eventName": "UpdateStack", "awsRegion": "us-east-1", "sourceIPAddress": "127.0.0.1", "userAgent": "aws-cli/1.2.11 Python/2.7.4 Linux/2.6.18-164.el5", "requestParameters": { "templateURL": "
templateURL
", "parameters": [ { "parameterKey": "password" }, { "parameterKey": "securitygroup" } ], "stackName": "my-test-stack" }, "responseElements": { "stackId": "arn:aws:cloudformation:us-east-1:012345678910:stack/my-test-stack/a38e6a60-b397-11e3-b0fc-08002755629e" }, "requestID": "def0bf5a-b397-11e3-bb75-a5b75389b02d", "eventID": "637707ce-e4a3-4af1-8edc-16e37e851b17" }
The following example shows that Alice called the ListStacks
operation.
{ "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "AIDAABCDEFGHIJKLNMOPQ", "arn": "arn:aws:iam::012345678910:user/Alice", "accountId": "012345678910", "accessKeyId": "AKIDEXAMPLE", "userName": "Alice" }, "eventTime": "2014-03-24T21:03:16Z", "eventSource": "cloudformation.amazonaws.com", "eventName": "ListStacks", "awsRegion": "us-east-1", "sourceIPAddress": "127.0.0.1", "userAgent": "aws-cli/1.2.11 Python/2.7.4 Linux/2.6.18-164.el5", "requestParameters": null, "responseElements": null, "requestID": "b7d351d7-b397-11e3-bb75-a5b75389b02d", "eventID": "918206d0-7281-4629-b778-b91eb0d83ce5" }
The following example shows that Alice called the DescribeStacks
operation on
the my-test-stack
stack.
{ "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "AIDAABCDEFGHIJKLNMOPQ", "arn": "arn:aws:iam::012345678910:user/Alice", "accountId": "012345678910", "accessKeyId": "AKIDEXAMPLE", "userName": "Alice" }, "eventTime": "2014-03-24T21:06:15Z", "eventSource": "cloudformation.amazonaws.com", "eventName": "DescribeStacks", "awsRegion": "us-east-1", "sourceIPAddress": "127.0.0.1", "userAgent": "aws-cli/1.2.11 Python/2.7.4 Linux/2.6.18-164.el5", "requestParameters": { "stackName": "my-test-stack" }, "responseElements": null, "requestID": "224f2586-b398-11e3-bb75-a5b75389b02d", "eventID": "9e5b2fc9-1ba8-409b-9c13-587c2ea940e2" }
The following example shows that Alice called the DeleteStack
operation on
the my-test-stack
stack.
{ "eventVersion": "1.01", "userIdentity": { "type": "IAMUser", "principalId": "AIDAABCDEFGHIJKLNMOPQ", "arn": "arn:aws:iam::012345678910:user/Alice", "accountId": "012345678910", "accessKeyId": "AKIDEXAMPLE", "userName": "Alice" }, "eventTime": "2014-03-24T21:07:15Z", "eventSource": "cloudformation.amazonaws.com", "eventName": "DeleteStack", "awsRegion": "us-east-1", "sourceIPAddress": "127.0.0.1", "userAgent": "aws-cli/1.2.11 Python/2.7.4 Linux/2.6.18-164.el5", "requestParameters": { "stackName": "my-test-stack" }, "responseElements": null, "requestID": "42dae739-b398-11e3-bb75-a5b75389b02d", "eventID": "4965eb38-5705-4942-bb7f-20ebe79aa9aa" }