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

tsas

v0.0.26

Published

A command line tool for AWS Lambda TypeScript function.

Downloads

33

Readme

This is alpha. Do not use for your production.

TSAS - TypeScript Application for Serverless

A command line tool, supports AWS serverless application development.

  • Create AWS serverless project template (TypeScript, node).
  • Manage parameters by AWS Systems Manager parameter store.
  • Deploy Lambda Function using AWS SAM.
  • Deploy AWS resources using AWS CloudFormation.

Installation

npm i -g tsas

Usage

tsas -h
---
Usage: tsas COMMAND

Commands:
  tsas init     Create a new, empty Typed Lambda project from a template.
  tsas param    Manage application parameters, [push|list]
  tsas deploy   Deploy aws resources, [serverless|sls|cloudformation|cfn]
  tsas display  Display information [cfn-parameters]

Options:
  --version   Show version number                                      [boolean]
  --region    Use the indicated AWS region to override default in config file.
                                                                        [string]
  --env, -e   Environment name; such as dev, stg, prod...               [string]
  --verbose   Set verbose mode.                       [boolean] [default: false]
  -h, --help  Show help                                                [boolean]

Requirements

AWS accessible CLI. See:

If you need to switch role, you can use these helpful tools.

Create project using template.

mkdir hello-world
cd hello-world

tsas init

Push parameters

environments/${env}/parameters.json has application parameters. This tool uses parameter store for CloudFormation deploy, so you should push local parameters to aws, at first.

tsas param push --env stg
tsas param list --env stg

Deploy lambda function (and function's IAM role )

tsas deploy serverless --env stg 

Deploy resources using pure CloudFormation template

tsas deploy cloudformation dynamodb --env stg 

Test invoke

Using aws/aws-cli: Universal Command Line Interface for Amazon Web Services.

aws lambda invoke --function-name <your-function-name> --log-type Tail \
--payload '{"name":"Bob"}' \
outputfile.txt

DynamoDB table greeting will have been updated.

How it works

arch.png

  • Manage parameters used in the whole application with a parameter store.
  • Deploy Lambda Function using AWS SAM.
  • Deploy AWS resources using CloudFormation.

As you see, within this tool, you do not need to include the Parameters section in your SAM or CloudFormation templates.

Develop your application

Edit parameters

environments/${env}/parameters.json has application parameters. If you want to add/modify parameters, edit the json file and re-push to parameter store, using:

tsas param push --env stg

If you want to confirm CloudFormation Parameter section, use:

tsas display cfn-parameters --env stg

Put / Override individual parameter, such as server-side access key, secret key.

If you don't want to write paramter to variables.json, use this command.

tsas param put <key> <value>

tsas param put AccessKey LFIOPWEPJSD23423ALGFJ --env stg
tsas param put AccessSecret afasdgbaj==awefaebasdvmkls--__ --env stg

Add Lambda function

There are 3 steps.

  1. Add TypeScript source code.
  2. Append entry to webpack.config.js.
  3. Append the function information to lambda.yaml.

Source code

src/handlers has lambda function entry point. So, you can start developing new functions by adding files to handlers.

webpack.config.js

After that, edit webpack.config.js to entry new function.

...
module.exports = {
    mode: 'development',
    target: 'node',
    entry: {
       'hello-world': path.resolve(__dirname, './src/lambda/handlers/api-gw/api-gw-greeting.ts'),

        // add ( example )
        'next-step': path.resolve(__dirname, './src/lambda/handlers/api-gw/api-gw-next-step.ts'), 
    }
...    

lambda.yaml

Finally, edit templates/lambda.yaml.

Resources:
  HelloWorldHelloLambda:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub ${Env}-${AppName}-hello
      Role: !GetAtt HelloWorldLambdaRole.Arn
      Handler: hello-world/index.handler
      Runtime: nodejs8.10
      CodeUri:
        Bucket: !Ref DeployBucketName
        Key: !Sub ${ChangeSetHash}/dist.zip
      Timeout: 5
      Environment:
        Variables:
          ENV: !Ref Env
          GREETING_TABLE_NAME: !Ref GreetingTableName
          REGION: !Ref AWS::Region
            
  HelloWorldNextStepLambda: # Add
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub ${Env}-${AppName}-next-step
      Role: !GetAtt HelloWorldLambdaRole.Arn
      Handler: next-step/index.handler
      Runtime: nodejs8.10
      CodeUri:
        Bucket: !Ref DeployBucketName
        Key: !Sub ${ChangeSetHash}/dist.zip
      Timeout: 5
      Environment:
        Variables:
          ENV: !Ref Env
          REGION: !Ref AWS::Region

Other AWS resources

  1. Add CloudFormation template file or append to exists.
  2. Deploy with a name.

tsas deploy cloudformation <template_name> needs target template name, such as:

tsas deploy cloudformation dynamodb --env stg

The <template_name> is required to match the CloudFormation template file name, so above command will deploy templates/dynamodb.yaml. You can add new resources by following steps.

touch templates/s3.yaml
### edit file ###
tsas deploy cloudformation s3 --env stg

Other Environments

Initial templates only refers to the stg environment. You can define ather environments. Even in different environments, above flow is the same. You only need to create a new environment setting file.

touch environments/prd/variables.json
### edit json file ###

After that, adjust --env option.

tsas param push --env prd
tsas deploy serverless --env prd 
tsas deploy cloudformation dynamodb --env prd