AWS CloudFormation
User Guide (API Version 2010-05-15)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

在 AWS CloudTrail 中记录 AWS CloudFormation API 调用

AWS CloudFormation 与 AWS CloudTrail 集成在一起,后者是一项服务,用于捕获由 AWS 账户执行或代表 AWS 账户执行的 API 调用。这种信息经过收集后,写入存储在您指定的 Amazon S3 存储桶中的日志文件中。当您使用 AWS CloudFormation API、AWS CloudFormation 控制台(一个后端控制台)或 AWS CLI 时,会记录 API 调用。通过使用 CloudTrail 收集的信息,您可以确定向 AWS CloudFormation 发出了什么请求、发出请求的源 IP 地址、何人发出请求以及发出请求的时间等。

要了解有关 CloudTrail 的更多信息,包括如何对其进行配置和启用,请参阅 AWS CloudTrail User Guide

CloudTrail 中的 AWS CloudFormation 信息

如果启用 CloudTrail 日志记录,则对所有 AWS CloudFormation 操作的调用都会捕获在日志文件中。所有 AWS CloudFormation 操作都记录在 AWS CloudFormation API Reference 中。举例来说,对 CreateStackDeleteStackListStacks 操作的调用会在 CloudTrail 日志文件中生成相关条目。

每个日志条目都包含有关生成请求的人员的信息。举例来说,如果发出请求以列出 AWS CloudFormation 堆栈 (ListStacks),则 CloudTrail 会记录发出请求的人员或服务的用户身份。用户身份信息有助于确定发出的请求是否具有根或 IAM 用户凭证,是否具有角色或联合用户临时安全凭证,或者是否由其他 AWS 服务发出。有关 CloudTrail 字段的更多信息,请参阅 AWS CloudTrail User Guide中的 CloudTrail 事件引用

日志文件可以在存储桶中存储任意长时间,不过您也可以定义 Amazon S3 生命周期规则以自动存档或删除日志文件。默认情况下,将使用 Amazon S3 服务器端加密 (SSE) 对日志文件进行加密。

了解 AWS CloudFormation 日志文件条目

CloudTrail 日志文件可包含一个或多个日志条目,每个条目由多个 JSON 格式的事件组成。一个日志条目表示来自任何源的一个请求,并包括所请求的操作、所有输入参数以及操作的日期和时间等信息。日志条目不按任何特定顺序显示。也就是说,它们不表示公用 API 调用的有序堆栈跟踪。

下面的示例记录显示 CreateStack 操作的 CloudTrail 日志条目。该操作由名为 Alice 的 IAM 用户执行。

注意

仅记录输入参数键名称;不记录参数值。

{ "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": "https://s3.amazonaws.com/Alice-dev/create_stack", "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" }

下面的示例记录显示 Alice 对 my-test-stack 堆栈调用了 UpdateStack 操作:

{ "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": "https://s3.amazonaws.com/Alice-dev/create_stack", "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" }

下面的示例记录显示 Alice 调用了 ListStacks 操作。

{ "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" }

下面的示例记录显示 Alice 对 my-test-stack 堆栈调用了 DescribeStacks 操作。

{ "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" }

下面的示例记录显示 Alice 对 my-test-stack 堆栈调用了 DeleteStack 操作。

{ "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" }