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

sam-local-windows-install

v1.0.0

Published

SAM Local Hello World Sample

Downloads

1

Readme

SAM Local Installation

Install SAM Local on Windows 10 Enterprise. Test SAM Local with a simple Lambda function.

According to AWS, 'sam is the AWS CLI tool for managing Serverless applications written with AWS Serverless Application Model (SAM). SAM Local can be used to test functions locally, start a local API Gateway from a SAM template, validate a SAM template, and generate sample payloads for various event sources.'

Install Docker for Windows

SAM Local requires Docker. Link to Docker for Windows. Choose the Stable or Edge version of Docker for Windows.

Docker

You will need to close and logout.

Docker

Windows will ask you to restart to enable Hyper-V and Containers features.

Docker

Install AWS SAM Local

Install aws-sam-local npm package globally. Assumes Node.js/npm already installed.

npm install -g aws-sam-local
sam --version

Node

Sample Lambda Function

Example is a combination of several public AWS samples.

Lambda: index.js

'use strict';

console.log('Loading function');

exports.handler = (event, context, callback) => {
  console.log('Received event:', JSON.stringify(event, null, 2));
  console.log('value1 =', event.key1);
  console.log('value2 =', event.key2);
  console.log('value3 =', event.key3);
  callback(null, {
    statusCode: 200,
    headers: {
      "x-custom-header": event.key1
    },
    body: event.key2
  });
};

Test Event: event.json

{
  "key3": "Lambda",
  "key2": "Serverless",
  "key1": "API Gateway"
}

SAM Template: template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: A starter AWS Lambda function.
Resources:
  helloworld:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      CodeUri: .
      Description: A starter AWS Lambda function.
      MemorySize: 128
      Timeout: 3
      Events:
        Api:
          Type: Api
          Properties:
            Path: /test
            Method: get

Invoke Lambda with an Event file

To test SAM Local, execute npm test or sam local invoke -e event.json.

Node

The first time you run SAM Local, you will need to share access to your C: drive.

Docker

Deploy API to AWS

Execute the two commands below to deploy of the Lambda function and associated API to AWS, using SAM. Commands require you have sufficient privileges to AWS resources.

These commands will create an S3 bucket (you will need to substitute a unique bucket name for the bucket), API, in the API Gateway, titled test-api, matching the CloudFormation stack name. The Lambda will also be created, titled similar to test-stack-helloworld-1SOIAN9J9EUJS. The Lambda function will be associated with the GET method of the /test API endpoint.

aws s3 mb s3://<unique_bucket_name>

aws cloudformation package \
  --template-file template.yaml \
  --s3-bucket <unique_bucket_name> \
  --output-template-file packaged-template.yaml

aws cloudformation deploy \
  --template-file packaged-template.yaml \
  --stack-name test-api \
  --capabilities CAPABILITY_IAM

SAM Local References