From 466bbc4d4e689df2c6d9be033525298865c09d04 Mon Sep 17 00:00:00 2001 From: Bobby Yu Date: Mon, 13 Jan 2025 09:46:31 -0800 Subject: [PATCH 1/2] added enable logging page --- cspell.json | 1 + src/directory/directory.mjs | 3 + .../data/enable-logging/index.mdx | 111 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx diff --git a/cspell.json b/cspell.json index 1a8cb5adc24..7dcc2cc6dd3 100644 --- a/cspell.json +++ b/cspell.json @@ -494,6 +494,7 @@ "dataaccess", "dataacess", "databinding", + "datalogconfig", "dataset", "datasource", "DataSource", diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index ac9069cd84f..4437768235f 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -340,6 +340,9 @@ export const directory = { }, { path: 'src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx' + }, + { + path: 'src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx' } ] }, diff --git a/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx b/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx new file mode 100644 index 00000000000..02aced55669 --- /dev/null +++ b/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx @@ -0,0 +1,111 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Enable logging', + description: 'Learn how to enable logging for your Amplify data resource', + platforms: [ + 'android', + 'angular', + 'flutter', + 'javascript', + 'nextjs', + 'react', + 'react-native', + 'swift', + 'vue' + ] +}; + +export function getStaticPaths() { + return getCustomStaticPath(meta.platforms); +} + +export function getStaticProps(context) { + return { + props: { + platform: context.params.platform, + meta + } + }; +} + +You can enable logging to debug your GraphQL API using Amazon CloudWatch logs. To learn more about logging and monitoring capabilities for your GraphQL API, visit the [AWS AppSync documentation for logging and monitoring](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html). + +## Enable default logging configuration + +Default logging can be enabled by setting the `logging` property to `true` in the call to `defineData`. For example: + +```ts title="amplify/data/resource.ts" +export const data = defineData({ + // ... + logging: true +}); +``` + +Using `logging: true` applies the default configuration: +- `excludeVerboseContent: true` (see AppSync's [Request-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl)) +- `fieldLogLevel: 'none'` (see AppSync's [Field-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl)) +- `retention: '1 week'` (see [Enum RetentionDays](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html)) + +## Customize logging configuration + +You can customize individual configuration values by providing a [`DataLogConfig`](#datalogconfig-fields) object. For example: + +```ts title="amplify/data/resource.ts" +export const data = defineData({ + // ... + logging: { + excludeVerboseContent: false, + fieldLogLevel: 'all', + retention: '1 month' + } +}); +``` + + +**WARNING**: Setting `excludeVerboseContent` to `false` logs full queries and user parameters, which can contain sensitive data. We recommend limiting CloudWatch log access to only those roles or users (e.g., DevOps or developers) who genuinely require it, by carefully scoping your IAM policies. + + +## Configuration Properties + +### `logging` +- `true`: Enables default logging. +- `DataLogConfig` object: Overrides one or more default fields. + +### `DataLogConfig` Fields + +- **`excludeVerboseContent?: boolean`** + - Defaults to `true` + - When `false`, logs can contain request-level logs. See [AppSync's Request-Level Logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl). + +- **`fieldLogLevel?: DataLogLevel`** + - Defaults to `'none'` + - Supported values of [AppSync's Field Log Levels](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl): + - `'none'` + - `'error'` + - `'info'` + - `'debug'` + - `'all'` + +- **`retention?: LogRetention`** + - Number of days to keep the logs + - Defaults to `'1 week'` + - Supported values of [Enum RetentionDays](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html): + - `'1 day'` + - `'3 days'` + - `'5 days'` + - `'1 week'` + - `'2 weeks'` + - `'1 month'` + - `'2 months'` + - `'3 months'` + - `'4 months'` + - `'5 months'` + - `'6 months'` + - `'1 year'` + - `'13 months'` + - `'18 months'` + - `'2 years'` + - `'5 years'` + - `'10 years'` + - `'infinite'` From 3f352bba5accfbd31d114a5ef553f35744a81549 Mon Sep 17 00:00:00 2001 From: Bobby Yu Date: Mon, 13 Jan 2025 09:49:10 -0800 Subject: [PATCH 2/2] update link --- .../[platform]/build-a-backend/data/enable-logging/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx b/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx index 02aced55669..71080dc4856 100644 --- a/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx @@ -43,8 +43,8 @@ export const data = defineData({ ``` Using `logging: true` applies the default configuration: -- `excludeVerboseContent: true` (see AppSync's [Request-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl)) -- `fieldLogLevel: 'none'` (see AppSync's [Field-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl)) +- `excludeVerboseContent: true` (see [AppSync's Request-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl)) +- `fieldLogLevel: 'none'` (see [AppSync's Field-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl)) - `retention: '1 week'` (see [Enum RetentionDays](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html)) ## Customize logging configuration