Logging Amplify API calls using AWS CloudTrail - AWS Amplify Hosting

Logging Amplify API calls using AWS CloudTrail

AWS Amplify is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in Amplify. CloudTrail captures all API calls for Amplify as events. The calls captured include calls from the Amplify console and code calls to the Amplify API operations. If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for Amplify. 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 that CloudTrail collects, you can determine the request that was made to Amplify, 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.

Amplify information in CloudTrail

CloudTrail is enabled on your AWS account by default. When activity occurs in Amplify, 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 in the AWS CloudTrail User Guide.

For an ongoing record of events in your AWS account, including events for Amplify, 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 AWS 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 the following in the AWS CloudTrail User Guide:

All Amplify operations are logged by CloudTrail and are documented in the AWS Amplify Console API Reference, the AWS Amplify Admin UI API Reference, and the Amplify UI Builder API Reference. For example, calls to the CreateApp, DeleteApp and DeleteBackendEnvironment operations 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:

  • Was the request made with root or AWS Identity and Access Management (IAM) user credentials.

  • Was the request made with temporary security credentials for a role or federated user.

  • Was the request made by another AWS service.

For more information, see the CloudTrail userIdentity element in the AWS CloudTrail User Guide.

Understanding Amplify 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 action, the date and time of the action, 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 AWS Amplify Console API Reference ListApps operation.

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::444455556666:user/Mary_Major", "accountId": "444455556666", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-01-12T05:48:10Z" } } }, "eventTime": "2021-01-12T06:47:29Z", "eventSource": "amplify.amazonaws.com", "eventName": "ListApps", "awsRegion": "us-west-2", "sourceIPAddress": "192.0.2.255", "userAgent": "aws-internal/3 aws-sdk-java/1.11.898 Linux/4.9.230-0.1.ac.223.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.275-b01 java/1.8.0_275 vendor/Oracle_Corporation", "requestParameters": { "maxResults": "100" }, "responseElements": null, "requestID": "1c026d0b-3397-405a-95aa-aa43aexample", "eventID": "c5fca3fb-d148-4fa1-ba22-5fa63example", "readOnly": true, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "444455556666" }

The following example shows a CloudTrail log entry that demonstrates the AWS Amplify Admin UI API Reference ListBackendJobs operation.

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "AIDACKCEVSQ6C2EXAMPLE", "arn": "arn:aws:iam::444455556666:user/Mary_Major", "accountId": "444455556666", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Mary_Major", "sessionContext": { "sessionIssuer": {}, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-01-13T00:47:25Z" } } }, "eventTime": "2021-01-13T01:15:43Z", "eventSource": "amplifybackend.amazonaws.com", "eventName": "ListBackendJobs", "awsRegion": "us-west-2", "sourceIPAddress": "192.0.2.255", "userAgent": "aws-internal/3 aws-sdk-java/1.11.898 Linux/4.9.230-0.1.ac.223.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.275-b01 java/1.8.0_275 vendor/Oracle_Corporation", "requestParameters": { "appId": "d23mv2oexample", "backendEnvironmentName": "staging" }, "responseElements": { "jobs": [ { "appId": "d23mv2oexample", "backendEnvironmentName": "staging", "jobId": "ed63e9b2-dd1b-4bf2-895b-3d5dcexample", "operation": "CreateBackendAuth", "status": "COMPLETED", "createTime": "1610499932490", "updateTime": "1610500140053" }, { "appId": "d23mv2oexample", "backendEnvironmentName": "staging", "jobId": "06904b10-a795-49c1-92b7-185dfexample", "operation": "CreateBackend", "status": "COMPLETED", "createTime": "1610499657938", "updateTime": "1610499704458" } ], "appId": "d23mv2oexample", "backendEnvironmentName": "staging" }, "requestID": "7adfabd6-98d5-4b11-bd39-c7deaexample", "eventID": "68769310-c96c-4789-a6bb-68b52example", "readOnly": false, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "444455556666" }