New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

aws-ts

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-ts

This package lets you handle and send responses from AWS lambda with ease. You have the ability to send various types of responses such as JSON or Plain Text without worrying about headers and status codes. You can also enable or disable cors for all or s

latest
Source
npmnpm
Version
1.0.14
Version published
Maintainers
1
Created
Source

AWS-TS

This package lets you handle and send responses from AWS lambda with ease. You have the ability to send various types of responses such as JSON or Plain Text without worrying about headers and status codes. You can also enable or disable cors for all or specific responses or set custom headers.

Installation

yarn add aws-ts

OR

npm install aws-ts

Basic Example

import { HttpResponse } from "aws-ts";
// or
// const { HttpResponse } = require('aws-ts')

const httpResponse = new HttpResponse();

export const handler = async (event) => {
  const data = {
    message: "Hey there",
  };

  return httpResponse.successResponse(data).json;
};

Sending HTML as response

import { HttpResponse } from "aws-ts";

const httpResponse = new HttpResponse();

export const handler = async (event) => {
  const html = "<h1>Hey there</h1>";

  return httpResponse.html(html);
};

Setting up custom headers

import { HttpResponse } from "aws-ts";

const httpResponse = new HttpResponse();

export const handler = async (event) => {
  const data = {
    message: "Hey there",
  };

  const headers = {
    Authorization: "Bearer x3*********",
  };

  return httpResponse.successResponse(data, headers).json;
};

Setting up custom statusCodes

import { HttpResponse } from "aws-ts";

const httpResponse = new HttpResponse();

export const handler = async (event) => {
  const data = {
    message: "Hey there",
  };

  const headers = {
    Authorization: "Bearer x3*********",
  };

  return httpResponse.status(304).successResponse(data, headers).json;
};

Enabling CORS

const httpResponse = new HttpResponse({ enableCors: true });

Example

import { HttpResponse } from "aws-ts";

const httpResponse = new HttpResponse({ enableCors: true });

export const handler = async (event) => {
  const data = {
    message: "Hey there",
  };

  const headers = {
    Authorization: "Bearer x3*********",
  };

  return httpResponse.status(304).successResponse(data, headers).json;
};

Enabling CORS for specific handler

return httpResponse.successResponse(data).withCors().json;

Example:

import { HttpResponse } from "aws-ts";

const httpResponse = new HttpResponse();

export const handler = async (event) => {
  const data = {
    message: "Hey there",
  };

  const headers = {
    Authorization: "Bearer x3*********",
  };

  return httpResponse.status(304).successResponse(data, headers).withCors()
    .json;
};

Keywords

aws-lambda

FAQs

Package last updated on 14 Aug 2021

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