Skip to content

Commit 0951f8d

Browse files
committed
docs(quickstart): sentence fragmentation, tidy up
1 parent bb71ce5 commit 0951f8d

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

docs/quickstart.md

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ This quickstart progressively introduces Lambda Powertools core utilities by usi
88
## Requirements
99

1010
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html){target="_blank"} and [configured with your credentials](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-set-up-credentials.html){target="_blank"}.
11-
* [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html){target="_blank"} installed.
11+
* [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html){target="_blank"} installed.
1212

1313
## Getting started
14+
1415
Let's clone our sample project before we add one feature at a time.
1516

1617
???+ tip "Tip: Want to skip to the final project?"
1718
Bootstrap directly via SAM CLI: `sam init --location https://github.com/aws-samples/cookiecutter-aws-sam-python`
18-
=== "shell"
19-
```bash
19+
20+
```bash title="Use SAM CLI to initialize the sample project"
2021
sam init --runtime python3.9 --dependency-manager pip --app-template hello-world --name powertools-quickstart
2122
```
2223

2324
### Project structure
25+
2426
As we move forward, we will modify the following files within the `powertools-quickstart` folder:
2527

2628
* **app.py** - Application code.
2729
* **template.yaml** - AWS infrastructure configuration using SAM.
2830
* **requirements.txt** - List of extra Python packages needed.
2931

3032
### Code example
33+
3134
Let's configure our base application to look like the following code snippet.
35+
3236
=== "app.py"
3337

3438
```python
@@ -74,37 +78,40 @@ Let's configure our base application to look like the following code snippet.
7478
```
7579
Our Lambda code consists of an entry point function named `lambda_handler`, and a `hello` function.
7680

77-
When API Gateway receives a request, Lambda will call our `lambda_handler` function, subsequently calling the `hello` function. API Gateway will use this response to return the correct HTTP Status Code and payload back to the caller.
78-
The SAM model configures API Gateway, which redirects traffic to Lambda for one path only: `hello`.
81+
When API Gateway receives a HTTP GET request on `/hello` route, Lambda will call our `lambda_handler` function, subsequently calling the `hello` function. API Gateway will use this response to return the correct HTTP Status Code and payload back to the caller.
82+
7983
!!! Warning
80-
For simplicity, we do not set up authentication and authorization in the example! Feel free to [implement](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-controlling-access-to-apis.html) it on your own.
84+
For simplicity, we do not set up authentication and authorization! You can find more information on how to implement it on [AWS SAM documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-controlling-access-to-apis.html){target="_blank"}.
8185
### Run your code
82-
At each point, you have two ways to run your code. Locally and within your AWS account. Given that we use SAM, the two methods are just as simple.
86+
87+
At each point, you have two ways to run your code: locally and within your AWS account.
88+
8389
#### Local test
84-
SAM allows you to execute a serverless application locally. Perform the next command in a shell.
85-
```bash
90+
91+
AWS SAM allows you to execute a serverless application locally by running `sam build && sam local start-api` in your preferred shell.
92+
93+
```bash title="Build and run API Gateway locally"
8694
> sam build && sam local start-api
8795
...
8896
2021-11-26 17:43:08 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
8997
```
90-
As a result API endpoint will be exposed for you. You can trigger it with the `curl` command like in the following example.
91-
```bash
98+
99+
As a result, a local API endpoint will be exposed and you can invoke it using your browser, or your preferred HTTP API client e.g., [Postman](https://www.postman.com/downloads/){target="_blank"}, [httpie](https://httpie.io/){target="_blank"}, etc.
100+
101+
```bash title="Invoking our function locally via curl"
92102
> curl http://127.0.0.1:3000/hello
93103
{"message": "hello unknown!"}
94104
```
105+
95106
!!! info
96-
To learn more about local testing, please visit [SAM local testing](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html) page
97-
???+ tip "Tip: Want to use different tool for API testing?"
98-
Instead of `curl` you have many other options to choose from.
107+
To learn more about local testing, please visit the [AWS SAM CLI local testing](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html) documentation.
99108

100-
* Choose different command line tool like `HTTPie`.
101-
* Type the url in the browser directly
102-
* Use REST API client like `Postman` or `SoupUI`.
103-
!!! warning
104-
**Powertools Tracer** requires X-RAY service to work. This means that you will not see the traces locally. Roll it out on your AWS account instead.
105-
#### Remote test
106-
You may also deploy your application into AWS Account by issuing the following command.
107-
```bash
109+
110+
#### Live test
111+
112+
First, you need to deploy your application into your AWS Account by issuing `sam build && sam deploy --guided` command. This command builds a ZIP package of your source code, and deploy it to your AWS Account.
113+
114+
```bash title="Build and deploy your serverless application"
108115
> sam build && sam deploy --guided
109116
...
110117
CloudFormation outputs from deployed stack
@@ -125,14 +132,15 @@ Value arn:aws:lambda:eu-central-1:123456789012:function:sam-app-He
125132
------------------------------------------------------------------------------------------------------------------------------------------
126133
Successfully created/updated stack - sam-app in eu-central-1
127134
```
128-
This command builds a package and deploy it to your AWS Account. You find the API Gateway URL path against which you can launch requests in the output section.
129-
Now, you can trigger your endpoints.
130-
```bash
135+
136+
At the end of the deployment, you will find the API endpoint URL within `Outputs` section. You can use this URL to test your serverless application.
137+
138+
```bash title="Invoking our application via API endpoint"
131139
> curl https://1234567890.execute-api.eu-central-1.amazonaws.com/Prod/hello
132140
{"message": "hello unknown!"}%
133141
```
134142
!!! Info
135-
For more details on the SAM deployment mechanism, see [link](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html).
143+
For more details on AWS SAM deployment mechanism, see [SAM Deploy reference docs](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html).
136144

137145
## API Gateway router
138146
Let's expand our application with a new method. It takes an username as a input and return it in the response.
@@ -450,6 +458,10 @@ By having structured logs like this, we can easily search and analyse them in [C
450458
=== "CloudWatch Logs Insight Example"
451459
![CloudWatch Logs Insight Example](./media/cloudwatch_logs_insight_example.png)
452460
## Tracing
461+
462+
!!! warning
463+
**Tracer** uses AWS X-Ray and you will not see any traces when executing your function locally.
464+
453465
The next improvement is to add an appropriate tracking mechanism to your stack. Developers want to analyze traces of queries that pass via the API gateway to your Lambda.
454466
With structured logs, it is an important step to provide the observability of your application!
455467
The AWS service that has these capabilities is [AWS X-RAY](https://aws.amazon.com/xray/). How do we send application trace to the AWS X-RAY service then?

0 commit comments

Comments
 (0)