From 3cacee4ba231780fd8b10a487dfdcf2357730aa0 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Fri, 10 May 2024 11:57:46 -0400 Subject: [PATCH 1/4] fix(logging): set-up code snippets with backend.ts --- .../logging/set-up-logging/index.mdx | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx index 5c489a0bfef..cd402c63dbd 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx @@ -104,29 +104,20 @@ You will need to create a log group in Amazon CloudWatch to send logs to. You ca Below is a sample CDK construct to create the Amazon CloudWatch log group as well as creating and assigning the permission policies to Amplify roles. -The `` and `` configured in the CDK construct will be used later to initialize the Amplify Logger plugin. +First create the file `amplify/custom/RemoteLoggingConstraintsConstruct.resource.ts` with the following: -### Replace the placeholder values with your own values: - -- `` is the log group that logs will be sent to. Note that this CDK construct sample includes logic to create the CloudWatch log group that you may have already created in previous steps. -- `` and `` are Amplify roles created as part of Amplify Auth configuration via Amplify CLI. - -```ts +```ts title="RemoteLoggingConstraintsConstruct.resource.ts" import * as cdk from "aws-cdk-lib" import { Construct } from "constructs" import * as logs from "aws-cdk-lib/aws-logs" -import * as path from "path" import * as iam from "aws-cdk-lib/aws-iam" export class RemoteLoggingConstraintsConstruct extends Construct { - constructor(scope: Construct, id: string, props: RemoteLoggingConstraintProps) { + constructor(scope: Construct, id: string, authRoleName: string, unAuthRoleName: string, logGroupName: string) { super(scope, id) const region = cdk.Stack.of(this).region const account = cdk.Stack.of(this).account - const logGroupName = - const authRoleName = - const unAuthRoleName = new logs.LogGroup(this, 'Log Group', { logGroupName: logGroupName, @@ -151,7 +142,32 @@ export class RemoteLoggingConstraintsConstruct extends Construct { } ``` -The `` and `` will be printed out in the in the terminal. You can use this information to setup the Amplify library in the next section. +Then, update `backend.ts` and replace the `` with your own value. + +`` is the log group that logs will be sent to. + +```ts file="backend.ts" +import { defineBackend } from '@aws-amplify/backend'; +import { auth } from './auth/resource'; +// highlight-next-line +import { RemoteLoggingConstraintsConstruct } from './custom/RemoteLoggingConstraintsConstruct/resource'; + +const backend = defineBackend({ + auth +}); + +// highlight-start +const loggingConstruct = new RemoteLoggingConstraintsConstruct( + backend.createStack('logging-stack'), + 'logging-stack', + backend.auth.resources.authenticatedUserIamRole.roleName, + backend.auth.resources.unauthenticatedUserIamRole.roleName, + +); +// highlight-end +``` + +The `` and region will be printed out in the terminal. You can use this information to setup the Amplify library in the next section. ## Initialize Amplify Logging From 02971c4269dcdf6ed92b924b7c00eb55ce69c13b Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Fri, 10 May 2024 12:12:09 -0400 Subject: [PATCH 2/4] fix typo --- .../add-aws-services/logging/set-up-logging/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx index cd402c63dbd..1965b736fd6 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx @@ -104,9 +104,9 @@ You will need to create a log group in Amazon CloudWatch to send logs to. You ca Below is a sample CDK construct to create the Amazon CloudWatch log group as well as creating and assigning the permission policies to Amplify roles. -First create the file `amplify/custom/RemoteLoggingConstraintsConstruct.resource.ts` with the following: +Create the `RemoteLoggingConstraintsConstruct` custom CDK construct as the following: -```ts title="RemoteLoggingConstraintsConstruct.resource.ts" +```ts title="amplify/custom/RemoteLoggingConstraintsConstruct/resource.ts" import * as cdk from "aws-cdk-lib" import { Construct } from "constructs" import * as logs from "aws-cdk-lib/aws-logs" From 7acbf3ae3008a4d26b76585ecceadd023c92f887 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Tue, 21 May 2024 11:24:39 -0400 Subject: [PATCH 3/4] address PR comments --- .../logging/set-up-logging/index.mdx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx index 1965b736fd6..41759a05345 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx @@ -106,14 +106,20 @@ Below is a sample CDK construct to create the Amazon CloudWatch log group as wel Create the `RemoteLoggingConstraintsConstruct` custom CDK construct as the following: -```ts title="amplify/custom/RemoteLoggingConstraintsConstruct/resource.ts" +```ts title="amplify/custom/RemoteLoggingConstraints/resource.ts" import * as cdk from "aws-cdk-lib" import { Construct } from "constructs" import * as logs from "aws-cdk-lib/aws-logs" import * as iam from "aws-cdk-lib/aws-iam" -export class RemoteLoggingConstraintsConstruct extends Construct { - constructor(scope: Construct, id: string, authRoleName: string, unAuthRoleName: string, logGroupName: string) { +type RemoteLoggingConstraintProps = { + authRoleName: string; + unAuthRoleName: string; + logGroupName: string; +}; + +export class RemoteLoggingConstraints extends Construct { + constructor(scope: Construct, id: string, props: RemoteLoggingConstraintProps) { super(scope, id) const region = cdk.Stack.of(this).region @@ -160,9 +166,11 @@ const backend = defineBackend({ const loggingConstruct = new RemoteLoggingConstraintsConstruct( backend.createStack('logging-stack'), 'logging-stack', - backend.auth.resources.authenticatedUserIamRole.roleName, - backend.auth.resources.unauthenticatedUserIamRole.roleName, - + { + authRoleName: backend.auth.resources.authenticatedUserIamRole.roleName, + unAuthRoleName: backend.auth.resources.unauthenticatedUserIamRole.roleName, + logGroupName: + } ); // highlight-end ``` From a4c5b7a64d3d4741c28e54c18a6442b73a5855e6 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Tue, 21 May 2024 11:31:23 -0400 Subject: [PATCH 4/4] update quotes --- .../add-aws-services/logging/set-up-logging/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx index 41759a05345..8e34c9779de 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/logging/set-up-logging/index.mdx @@ -169,7 +169,7 @@ const loggingConstruct = new RemoteLoggingConstraintsConstruct( { authRoleName: backend.auth.resources.authenticatedUserIamRole.roleName, unAuthRoleName: backend.auth.resources.unauthenticatedUserIamRole.roleName, - logGroupName: + logGroupName: "" } ); // highlight-end