-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(logging): set-up code snippets with backend.ts #7569
Open
lawmicha
wants to merge
4
commits into
main
Choose a base branch
from
fix.logging.set-up
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,29 +104,26 @@ 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 `<log-group-name>` and `<region>` configured in the CDK construct will be used later to initialize the Amplify Logger plugin. | ||
Create the `RemoteLoggingConstraintsConstruct` custom CDK construct as the following: | ||
|
||
### Replace the placeholder values with your own values: | ||
|
||
- `<log-group-name>` 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. | ||
- `<amplify-authenticated-role-name>` and `<amplify-unauthenticated-role-name>` are Amplify roles created as part of Amplify Auth configuration via Amplify CLI. | ||
|
||
```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 path from "path" | ||
import * as iam from "aws-cdk-lib/aws-iam" | ||
|
||
export class RemoteLoggingConstraintsConstruct extends Construct { | ||
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 | ||
const account = cdk.Stack.of(this).account | ||
const logGroupName = <log-group-name> | ||
const authRoleName = <amplify-authenticated-role-name> | ||
const unAuthRoleName = <amplify-unauthenticated-role-name> | ||
|
||
new logs.LogGroup(this, 'Log Group', { | ||
logGroupName: logGroupName, | ||
|
@@ -151,7 +148,34 @@ export class RemoteLoggingConstraintsConstruct extends Construct { | |
} | ||
``` | ||
|
||
The `<log-group-name>` and `<region>` 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 `<log-group-name>` with your own value. | ||
|
||
`<log-group-name>` 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', | ||
{ | ||
authRoleName: backend.auth.resources.authenticatedUserIamRole.roleName, | ||
unAuthRoleName: backend.auth.resources.unauthenticatedUserIamRole.roleName, | ||
logGroupName: "<log-group-name>" | ||
} | ||
); | ||
// highlight-end | ||
``` | ||
|
||
The `<log-group-name>` and region will be printed out in the terminal. You can use this information to setup the Amplify library in the next section. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe i missed this but what prints the log group to the terminal? |
||
|
||
## Initialize Amplify Logging | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel like we can make this a single line