Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-smithy/server-apigateway

Package Overview
Dependencies
Maintainers
10
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-smithy/server-apigateway

Base components for Smithy services behind APIGateway

  • 1.0.0-alpha.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
10
Created
Source

smithy-typescript/server-apigateway

This package provides glue code to enable using a server sdk inside of apigateway.

Usage

Example

import { HttpRequest } from "@aws-sdk/protocol-http";
import {
  GreetingService as __GreetingService,
  SayHelloInput,
  SayHelloOutput,
  getGreetingServiceHandler,
} from "@greeting-service/service-greeting";
import { convertEvent, convertResponse } from "@aws-smithy/server-apigateway";
import { APIGatewayProxyEventV2, APIGatewayProxyResultV2, APIGatewayProxyHandlerV2 } from "aws-lambda";
class GreetingService implements __GreetingService {
  SayHello(input: SayHelloInput, request: HttpRequest): SayHelloOutput {
    return {
      greeting: `Hello ${input.name}! How is ${input.city}?`,
    };
  }
}
const serviceHandler = getGreetingServiceHandler(new GreetingService());
export const lambdaHandler: APIGatewayProxyHandlerV2 = async (
  event: APIGatewayProxyEventV2
): Promise<APIGatewayProxyResultV2> => {
  console.log(`Received event: ${JSON.stringify(event)}`);

  // Convert apigateway's lambda event to an HttpRequest.
  const convertedEvent = convertEvent(event);

  // Call the service handler, which will route the request to the GreetingService
  // implementation and then serialize the response to an HttpResponse.
  let rawResponse = await serviceHandler.handle(convertedEvent);

  // Convert the HttpResponse to apigateway's expected format.
  const convertedResponse = convertResponse(rawResponse);
  console.log(`Returning response: ${JSON.stringify(convertedResponse)}`);
  return convertedResponse;
};

FAQs

Package last updated on 18 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc