You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/app/README.md
+26-18
Original file line number
Diff line number
Diff line change
@@ -2,54 +2,61 @@
2
2
3
3
This is a deployable CDK app that deploys AWS Lambda functions as part of a CloudFormation stack. These Lambda functions use the utilities made available as part of Powertools for AWS Lambda (TypeScript) to demonstrate their usage.
4
4
5
-
> **Note**
6
-
> You will need to have a valid AWS Account in order to deploy these resources. These resources may incur costs to your AWS Account. The cost from **some services** are covered by the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) but not all of them. If you don't have an AWS Account follow [these instructions to create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
5
+
> [!Warning]
6
+
> You will need to have a valid AWS Account in order to deploy these resources. Many of the services in the example are covered [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) but you may incur charges if you exceed the free tier limits.
7
+
If you don't have an AWS Account follow [these instructions to create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
7
8
8
9
The example functions, located in the `functions` folder, are frontend by a REST API that is deployed using AWS API Gateway.
9
10
10
11
The API has three endpoints:
11
12
12
-
*`POST /` - Adds an item to the DynamoDB table
13
-
*`GET /` - Retrieves all items from the DynamoDB table
14
-
*`GET /{id}` - Retrieves a specific item from the DynamoDB table
13
+
*`POST /` - Adds an item to the DynamoDB table
14
+
*`GET /` - Retrieves all items from the DynamoDB table
15
+
*`GET /{id}` - Retrieves a specific item from the DynamoDB table
15
16
16
17
## Deploying the stack
17
18
18
-
* Navigate to this location of the repo in your terminal (`examples/cdk`)
19
-
*`npm ci`
20
-
*`npm run cdk deploy --all --profile <YOUR_AWS_PROFILE>`
19
+
> [!Note]
20
+
> The `examples/app` directory where this example is located is part of a monorepo. If you are interested in deploying the example only, follow the instructions below.
21
+
> If instead you are working on the monorepo and want to deploy the example, follow the instructions in the [CONTRIBUTING](../../CONTRIBUTING.md#dev-setup) doc, then run `npm run cdk deploy -w examples/app` from the project's root.
21
22
22
-
Note: Prior to deploying youmay need to run `cdk bootstrap aws://<YOU_AWS_ACCOUNT_ID>/<AWS_REGION> --profile <YOUR_AWS_PROFILE>`if you have not already bootstrapped your account for CDK.
23
+
If this is the first time you're using CDK in your AWS Account & AWS Region, you may need to run `npm run cdk bootstrap aws://<YOU_AWS_ACCOUNT_ID>/<AWS_REGION> --profile <YOUR_AWS_PROFILE>`to bootstrap your account for CDK.
23
24
24
-
> **Note**
25
-
> You can find your API Gateway Endpoint URL in the output values displayed after deployment.
25
+
Then, still from within the `examples/app` directory, run the following commands:
26
+
27
+
*`npm i --prefix ./` to install the dependencies
28
+
*`npm run cdk deploy` and follow the prompts to deploy the stack
29
+
30
+
When the deployment is complete, you will see the output values that include the API Gateway Endpoint URL.
26
31
27
32
## Execute the functions via API Gateway
28
33
29
34
Use the API Gateway Endpoint URL from the output values to execute the functions. First, let's add two items to the DynamoDB Table by running:
30
35
31
36
```bash
32
-
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myfirstitem","name":"Some Name for the first item"}' https://randomid12345.execute-api.eu-central-1.amazonaws.com/prod/
33
-
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myseconditem","name":"Some Name for the second item"}' https://randomid1245.execute-api.eu-central-1.amazonaws.com/prod/
37
+
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myfirstitem","name":"Some Name for the first item"}' https://<api-id>.execute-api.eu-central-1.amazonaws.com/prod/
38
+
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myseconditem","name":"Some Name for the second item"}' https://<api-id>.execute-api.eu-central-1.amazonaws.com/prod/
@@ -62,10 +69,11 @@ If we check the logs in CloudWatch, we can see that the logs are structured like
62
69
63
70
By having structured logs like this, we can easily search and analyse them in [CloudWatch Logs Insight](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html). Run the following query to get all messages for a specific `awsRequestId`:
As we have enabled tracing for our Lambda-Funtions, you can visit [AWS CloudWatch Console](https://console.aws.amazon.com/cloudwatch/) and see [Traces](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces) and a [Service Map](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-using-xray-maps.html) for our application.
@@ -76,4 +84,4 @@ To delete the sample application that you created, run the command below while i
0 commit comments