Skip to content

Commit e7b3a8a

Browse files
add streaming function logs docs (#7841)
* add streaming function logs docs * Update src/pages/[platform]/build-a-backend/functions/streaming-logs/index.mdx Co-authored-by: Amplifiyer <[email protected]> * rm multiline log callout, added note for chaining --out-file * clarify log output in terminal where sandbox is running --------- Co-authored-by: Amplifiyer <[email protected]>
1 parent 8ab9f63 commit e7b3a8a

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

src/directory/directory.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ export const directory = {
367367
{
368368
path: 'src/pages/[platform]/build-a-backend/functions/configure-functions/index.mdx'
369369
},
370+
{
371+
path: 'src/pages/[platform]/build-a-backend/functions/streaming-logs/index.mdx'
372+
},
370373
{
371374
path: 'src/pages/[platform]/build-a-backend/functions/grant-access-to-other-resources/index.mdx'
372375
},
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Streaming logs',
5+
description:
6+
'Stream execution logs directly to your terminal while Sandbox is running',
7+
platforms: [
8+
'android',
9+
'angular',
10+
'flutter',
11+
'javascript',
12+
'nextjs',
13+
'react',
14+
'react-native',
15+
'swift',
16+
'vue'
17+
]
18+
};
19+
20+
export function getStaticPaths() {
21+
return getCustomStaticPath(meta.platforms);
22+
}
23+
24+
export function getStaticProps(context) {
25+
return {
26+
props: {
27+
platform: context.params.platform,
28+
meta
29+
}
30+
};
31+
}
32+
33+
Amplify enables you to stream logs from your Function directly to your terminal while running [`ampx sandbox`](/[platform]/reference/cli-commands/#npx-ampx-sandbox). To get started, specify the `--stream-function-logs` option when starting sandbox:
34+
35+
```bash title="Terminal" showLineNumbers={false}
36+
npx ampx sandbox --stream-function-logs
37+
```
38+
39+
<Callout info>
40+
41+
**Note**: this feature is only available for [Sandbox](/[platform]/deploy-and-host/sandbox-environments/)
42+
43+
</Callout>
44+
45+
Streaming Function logs directly to your terminal enable faster debug iterations, and greater insight into your Functions' executions.
46+
47+
## Filtering
48+
49+
By default, Amplify will stream all of your Functions' logs. If you wish to only stream a subset of Functions you can specify a filter by Function name or a regular expression for Function names. For example, if you have a collection of [Auth triggers](/[platform]/build-a-backend/auth/customize-auth-lifecycle/triggers/) where the Function names include "auth"
50+
51+
```bash title="Terminal" showLineNumbers={false}
52+
npx ampx sandbox --stream-function-logs --logs-filter auth
53+
```
54+
55+
After you successfully deploy your personal cloud sandbox, start your frontend application, and sign up for the first time, you will see logs from your triggers' executions printed to the terminal where sandbox is running.
56+
57+
```console title="Terminal"
58+
> npx ampx sandbox --stream-function-logs --logs-filter auth
59+
...
60+
61+
✨ Total time: 158.44s
62+
63+
[Sandbox] Watching for file changes...
64+
File written: amplify_outputs.json
65+
[auth-pre-sign-up] 3:36:34 PM INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4
66+
[auth-pre-sign-up] 3:36:34 PM START RequestId: 685be2bd-5df1-4dd5-9eb1-24f5f6337f91 Version: $LATEST
67+
[auth-pre-sign-up] 3:36:34 PM END RequestId: 685be2bd-5df1-4dd5-9eb1-24f5f6337f91
68+
[auth-pre-sign-up] 3:36:34 PM REPORT RequestId: 685be2bd-5df1-4dd5-9eb1-24f5f6337f91 Duration: 4.12 ms Billed Duration: 5 ms Memory Size: 512 MB Max Memory Used: 67 MB Init Duration: 173.67 ms
69+
[auth-post-confirmation] 3:38:40 PM INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4
70+
[auth-post-confirmation] 3:38:40 PM START RequestId: fce69b9f-b257-4af8-8a6e-821f84a39ce7 Version: $LATEST
71+
[auth-post-confirmation] 3:38:41 PM 2024-07-19T22:38:41.209Z fce69b9f-b257-4af8-8a6e-821f84a39ce7 INFO processed 412f8911-acfa-41c7-9605-fa0c40891ea9
72+
[auth-post-confirmation] 3:38:41 PM END RequestId: fce69b9f-b257-4af8-8a6e-821f84a39ce7
73+
[auth-post-confirmation] 3:38:41 PM REPORT RequestId: fce69b9f-b257-4af8-8a6e-821f84a39ce7 Duration: 264.38 ms Billed Duration: 265 ms Memory Size: 512 MB Max Memory Used: 93 MB Init Duration: 562.19 ms
74+
[auth-pre-authentication] 3:38:41 PM INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4
75+
[auth-pre-authentication] 3:38:41 PM START RequestId: 9210ca3a-1351-4826-8544-123684765710 Version: $LATEST
76+
[auth-pre-authentication] 3:38:41 PM END RequestId: 9210ca3a-1351-4826-8544-123684765710
77+
[auth-pre-authentication] 3:38:41 PM REPORT RequestId: 9210ca3a-1351-4826-8544-123684765710 Duration: 3.47 ms Billed Duration: 4 ms Memory Size: 512 MB Max Memory Used: 67 MB Init Duration: 180.24 ms
78+
[auth-post-authentication] 3:38:42 PM INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4
79+
[auth-post-authentication] 3:38:42 PM START RequestId: 60c1d680-ea24-4a8b-93de-02d085859140 Version: $LATEST
80+
[auth-post-authentication] 3:38:42 PM END RequestId: 60c1d680-ea24-4a8b-93de-02d085859140
81+
[auth-post-authentication] 3:38:42 PM REPORT RequestId: 60c1d680-ea24-4a8b-93de-02d085859140 Duration: 4.61 ms Billed Duration: 5 ms Memory Size: 512 MB Max Memory Used: 68 MB Init Duration: 172.66 ms
82+
```
83+
84+
## Writing to a file
85+
86+
By default, Amplify will print logs to the terminal where sandbox is running, however you can alternatively write logs to a file by specifying `--logs-out-file`:
87+
88+
```bash title="Terminal" showLineNumbers={false}
89+
npx ampx sandbox --stream-function-logs --logs-out-file sandbox.log
90+
```
91+
92+
This can be combined with `--logs-filter` to create a log file of just your Auth-related Functions, for example:
93+
94+
```bash title="Terminal" showLineNumbers={false}
95+
npx ampx sandbox --stream-function-logs --logs-filter auth --logs-out-file sandbox-auth.log
96+
```
97+
98+
However it cannot be combined multiple times to write logs to multiple files.

src/pages/[platform]/deploy-and-host/sandbox-environments/features/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ When working with multiple sandboxes, secrets must be configured for each one. A
166166
npx ampx sandbox --identifier feature1sandbox secret set baz
167167
```
168168

169+
## Stream function logs
170+
171+
Amplify offers the ability to stream function logs directly to your terminal or a file. [Learn more about streaming function logs](/[platform]/build-a-backend/functions/streaming-logs/).
172+
169173
## Generate client config
170174

171175
The client config, or `amplify_outputs.json` file, contains the configuration strings for interacting with AWS resources specific to an environment. The Amplify client libraries need the client config in order to use the library APIs to connect to backend resources. By default, the cloud sandbox generates the client configuration file at the root of the project (such as `@/amplify_outputs.json`). If you want to place the file at a different path (such as for a monorepo or Android app), run the following command in the terminal:

src/pages/[platform]/reference/cli-commands/index.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Sandbox enables you to develop your backend alongside your frontend's developmen
5656
- `--outputs-format` (_string_) - Format in which the client config file is written (choices: `json`, `dart`).
5757
- `--outputs-version` (_string_) - Version of the configuration. Version 0 represents classic amplify-cli config file amplify-configuration and 1 represents newer config file amplify_outputs (choices: `0`, `1`).
5858
- `--profile` (_string_) - An AWS profile name.
59+
- `--stream-function-logs` (_boolean_) - Whether to stream function execution logs. (default: false)
60+
- `--logs-filter` (_string[]_) - Regex pattern to filter logs from only matched functions. E.g. to stream logs for a function, specify it's name, and to stream logs from all functions starting with auth specify 'auth' (default: Stream all logs)
61+
- `--logs-out-file` (_string_) - File to append the streaming logs. The file is created if it does not exist. (default: stdout)
5962

6063
### Usage
6164

0 commit comments

Comments
 (0)