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

@jill64/types-lambda

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jill64/types-lambda

Unofficial AWS Lambda type definition

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.8K
increased by66.17%
Maintainers
1
Weekly downloads
 
Created
Source

types-lambda

npm-version npm-license npm-download-month npm-min-size

Unofficial AWS Lambda type definition

Install

npm i -D @jill64/types-lambda

Examples

Lambda (Function URL)

import type { LambdaHandler } from '@jill64/types-lambda'

const url = 'https://aws.amazon.com/'

export const handler: LambdaHandler = async (event) => {
  try {
    const res = await fetch(url)
    console.info('status', res.status)
    return res.status
  } catch (e) {
    console.error(e)
    return 500
  }
}

Lambda (Streaming Response)

import { awslambda } from '@jill64/types-lambda'

export const handler = awslambda.streamifyResponse(
  async (event, responseStream, _context) => {
    const metadata = {
      statusCode: 200,
      headers: {
        'Content-Type': 'application/json',
        CustomHeader: 'outerspace'
      }
    }

    responseStream = awslambda.HttpResponseStream.from(responseStream, metadata)

    responseStream.write('Streaming with Helper \n')
    responseStream.write('Hello 0 \n')
    responseStream.write('Hello 1 \n')
    responseStream.write('Hello 2 \n')
    responseStream.end()
    await responseStream.finished()
  }
)

Lambda@Edge

import type { OriginRequestHandler } from '@jill64/types-lambda'

export const handler: OriginRequestHandler = async (event, context) => {
  const response = event.Records[0].cf.response
  const headers = response.headers

  const headerNameSrc = 'X-Amz-Meta-Last-Modified'
  const headerNameDst = 'Last-Modified'

  if (headers[headerNameSrc.toLowerCase()]) {
    headers[headerNameDst.toLowerCase()] = [
      headers[headerNameSrc.toLowerCase()][0]
    ]
    console.log(
      `Response header "${headerNameDst}" was set to ` +
        `"${headers[headerNameDst.toLowerCase()][0].value}"`
    )
  }

  return response
}

Keywords

FAQs

Package last updated on 31 Oct 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