npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cdk-sample

v1.7.0

Published

This project contains source code and supporting files for a serverless application that you can deploy with CDK.

Downloads

9

Readme

AWS Lambda Powertools for TypeScript examples in CDK

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 AWS Lambda Powertools for TypeScript to demonstrate their usage.

Note 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 but not all of them. If you don't have an AWS Account follow these instructions to create one.

The example functions, located in the functions folder, are frontend by a REST API that is deployed using AWS API Gateway.

The API has three endpoints:

  • POST / - Adds an item to the DynamoDB table
  • GET / - Retrieves all items from the DynamoDB table
  • GET /{id} - Retrieves a specific item from the DynamoDB table

Deploying the stack

  • Navigate to this location of the repo in your terminal (examples/cdk)
  • npm ci
  • npm run cdk deploy --all --profile <YOUR_AWS_PROFILE>

Note: Prior to deploying you may 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.

Note You can find your API Gateway Endpoint URL in the output values displayed after deployment.

Execute the functions via API Gateway

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:

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/
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/

Now, let's retrieve all items by running:

curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/prod/

And finally, let's retrieve a specific item by running:

curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/prod/myseconditem/

Observe the outputs in AWS CloudWatch & X-Ray

CloudWatch

If we check the logs in CloudWatch, we can see that the logs are structured like this

2022-04-26T17:00:23.808Z	e8a51294-6c6a-414c-9777-6b0f24d8739b	DEBUG	
{
    "level": "DEBUG",
    "message": "retrieved items: 0",
    "service": "getAllItems",
    "timestamp": "2022-04-26T17:00:23.808Z",
    "awsRequestId": "e8a51294-6c6a-414c-9777-6b0f24d8739b"
}

By having structured logs like this, we can easily search and analyse them in CloudWatch Logs Insight. Run the following query to get all messages for a specific awsRequestId:

filter awsRequestId="bcd50969-3a55-49b6-a997-91798b3f133a"
 | fields timestamp, message

AWS X-Ray

As we have enabled tracing for our Lambda-Funtions, you can visit AWS CloudWatch Console and see Traces and a Service Map for our application.

Cleanup

To delete the sample application that you created, run the command below while in the examples/cdk directory:

cdk destroy