Logging AWS AppSync API calls with AWS CloudTrail - AWS AppSync GraphQL

Logging AWS AppSync API calls with AWS CloudTrail

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

AWS AppSync information in CloudTrail

CloudTrail is enabled on your AWS account when you create the account. When activity occurs in AWS AppSync, 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 AWS AppSync, 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:

AWS AppSync supports logging of calls made through the AWS AppSync API. At this time, calls to your APIs, as well as calls made to resolvers are not logged by AWS AppSync into CloudTrail.

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 AWS Identity and Access Management (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 AWS AppSync 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 GetGraphqlApi action made through the AWS AppSync console:

{ "eventVersion": "1.08", "userIdentity": { "type": "AssumedRole", "principalId": "ABCDEFXAMPLEPRINCIPAL:nikkiwolf", "arn": "arn:aws:sts::111122223333:assumed-role/admin/nikkiwolf", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AIDAJ45Q7YFFAREXAMPLE", "arn": "arn:aws:iam::111122223333:role/admin", "accountId": "111122223333", "userName": "admin" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2021-03-12T22:41:48Z" } } }, "eventTime": "2021-03-12T22:46:18Z", "eventSource": "appsync.amazonaws.com", "eventName": "GetGraphqlApi", "awsRegion": "us-west-2", "sourceIPAddress": "203.0.113.69", "userAgent": "aws-internal/3 aws-sdk-java/1.11.942 Linux/4.9.230-0.1.ac.223.84.332.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.282-b08 java/1.8.0_282 vendor/Oracle_Corporation", "requestParameters": { "apiId": "xhxt3typtfnmidkhcexampleid" }, "responseElements": null, "requestID": "2fc43a35-a552-4b5d-be6e-12553a03dd12", "eventID": "b95b0ad9-8c71-4252-a2ec-5dc2fe5f8ae8", "readOnly": true, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "111122223333" }

The following example shows a CloudTrail log entry that demonstrates the CreateApikey action made through the AWS CLI:

{ "eventVersion": "1.08", "userIdentity": { "type": "IAMUser", "principalId": "ABCDEFXAMPLEPRINCIPAL", "arn": "arn:aws:iam::111122223333:user/nikkiwolf", "accountId": "111122223333", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "nikkiwolf" }, "eventTime": "2021-03-12T22:49:10Z", "eventSource": "appsync.amazonaws.com", "eventName": "CreateApiKey", "awsRegion": "us-west-2", "sourceIPAddress": "203.0.113.69", "userAgent": "aws-cli/2.0.11 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev15", "requestParameters": { "apiId": "xhxt3typtfnmidkhcexampleid" }, "responseElements": { "apiKey": { "id": "***", "expires": 1616191200, "deletes": 1621375200 } }, "requestID": "e152190e-04ba-4d0a-ae7b-6bfc0bcea6af", "eventID": "ba3f39e0-9d87-41c5-abbb-2000abcb6013", "readOnly": false, "eventType": "AwsApiCall", "managementEvent": true, "eventCategory": "Management", "recipientAccountId": "111122223333" }