|
1 |
| -This is an initial attempt to test Lambda Powertools for TypeScript running on LocalStack. Currently there are just two basic examples of the Logger and the Tracer. |
| 1 | +## Powertools for AWS Lambda (TypeScript) in LocalStack |
2 | 2 |
|
3 |
| -You'll need to follow these steps to install all the dependencies before you can run this: |
| 3 | +[Powertools for AWS Lambda](https://docs.powertools.aws.dev/lambda/typescript/latest/) provide implementations of best practices for Lambda function development that are easy to integrate into your existing Lambda functions. |
| 4 | + |
| 5 | +This examples repository provides basic examples of the TypeScript implementation Powertools that can be run and tested in [LocalStack](https://localstack.cloud). The good news is that Powertools (including the logger, metrics, parameters, tracer and idempotency shown here) can be used "out of the box" in LocalStack. |
| 6 | + |
| 7 | +### Setup, Deployment and Testing the Examples |
| 8 | + |
| 9 | +The easiest way to test these examples is to use the provided Makefile. Start by installing the necessary dependencies: |
| 10 | + |
| 11 | +```bash |
| 12 | +make install |
| 13 | +``` |
| 14 | + |
| 15 | +Ensure that you have LocalStack running on your machine and then run the deploy command for the example you wish to run. For example: |
| 16 | + |
| 17 | +```bash |
| 18 | +make deploy-idempotency |
| 19 | +``` |
| 20 | + |
| 21 | +Once the deployment is finished, invoke the Lambda function. For example: |
| 22 | + |
| 23 | +```bash |
| 24 | +make invoke-idempotency |
| 25 | +``` |
| 26 | + |
| 27 | +### Manually Setup, Deployment and Testing the Examples |
| 28 | + |
| 29 | +The examples are set up to enable easy deployment and testing of the particular Powertool library you wish to use. Each example has a lambda folder containing the example Lambda and a CDK folder containing the CDK script needed to deploy the example. You will need the AWS CLI, AWS CDK CLI, LocalStack, `awslocal` and `cdklocal` installed. |
| 30 | + |
| 31 | +You'll need to run npm install within the directories for the example you wish to run. For instance: |
4 | 32 |
|
5 | 33 | ```bash
|
6 | 34 | cd tracer-lambda
|
7 | 35 | npm install
|
8 |
| -cd ../logger-lambda |
9 |
| -npm install |
10 |
| -cd ../cdk |
| 36 | +cd ../tracer-cdk |
11 | 37 | npm install
|
12 | 38 | ```
|
13 | 39 |
|
14 |
| -Now you can bootstrap and deploy using LocalStack's CDK wrapper. |
| 40 | +Next, you can bootstrap and deploy using LocalStack's CDK wrapper from within the CDK folder for the example you wish to deploy to LocalStack. |
15 | 41 |
|
16 | 42 | ```bash
|
17 | 43 | cdklocal bootstrap
|
18 | 44 | cdklocal deploy
|
19 | 45 | ```
|
20 | 46 |
|
21 |
| -The output will include the names of the deployed functions, which you can test using `awslocal` (replacing `PowerToolsCdkStack-loggerFunction` with the outputted function name): |
| 47 | +The output will include the names of the deployed functions, which you can test using `awslocal` (replacing `TracerStack-tracerFunction` with the outputted function name): |
22 | 48 |
|
23 | 49 | ```bash
|
24 |
| -awslocal lambda invoke --function-name PowerTools-loggerFunction output.txt |
| 50 | +awslocal lambda invoke --function-name TracerStack-tracerFunction output.txt |
25 | 51 | ```
|
26 |
| -At this point, the logger function output can be seen in CloudWatch. The tracer function just runs. Updating these with better examples soon. |
| 52 | +Note that the idempotency example does require passing a JSON payload containing a `productId` and `customer` (see the Makefile for an example on how to call this function manually). |
0 commit comments