0.0.15 • Published 4 months ago

serverless-standalone v0.0.15

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

serverless-standalone

Emulate AWS λ and aws-sdk locally when developing your Serverless node.js project

features

  • AWS WebSocket API + @aws-sdk/client-apigatewaymanagementapi
  • Schedule

demo

  • server: pnpm dev, see examples/dev.ts
  • client: wscat -c "ws://127.0.0.1:9001/path?foo=1&foo=2"
  • aws-sdk example: node ./examples/index.mjs {connectionId}

usage

define serverless function. similar with serverless.yml.

const websocket_connect: APIGatewayProxyHandler = async (event, context) => {
  ...
}
const websocket_disconnect: APIGatewayProxyHandler = async (event, context) => {
  ...
}

const definitions: FunctionDefinition[] = [
  {
    handler: websocket_connect,
    events: [{ websocket: { route: "$connect" } }],
  },
  {
    handler: websocket_disconnect,
    events: [{ websocket: { route: "$disconnect" } }],
  },
];

start serverless-standalone at localhost.

await StandAlone.start(definitions, {
  http: 9000,
  websocket: 9001,
  api: 9002,
});

connect websocket. aws lambda handler are invoked. wscat -c "ws://127.0.0.1:9001/path?username=me&password=pw"

use aws-sdk locally.

const client = new ApiGatewayManagementApiClient({
  region: "ap-northeast-1",
  endpoint: "http://127.0.0.1:9001/",
  credentials: {
    accessKeyId: "localAccessKeyId",
    secretAccessKey: "localAecretAccessKey",
  },
});

const output = await client.send(
  new PostToConnectionCommand({
    ConnectionId: connectionId,
    Data: new TextEncoder().encode("hello"),
  }),
);
0.0.12

4 months ago

0.0.13

4 months ago

0.0.14

4 months ago

0.0.15

4 months ago

0.0.11

4 months ago

0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago