Socket
Socket
Sign inDemoInstall

@dealmore/apollo-link-lambda

Package Overview
Dependencies
38
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dealmore/apollo-link-lambda

Apollo transport link for directly invoking AWS Lambda functions


Version published
Maintainers
1
Created

Readme

Source

Current npm version CI status

When your GraphQL endpoint is served by an AWS Lambda function, this Apollo link can be used as an in-place replacement for the HTTPLink. Instead of sending the GraphQL request over HTTP and API Gateway to your Lambda it uses the JavaScript AWS SDK to invoke the GraphQL Lambda directly.

This reduces the network overhead and costs because the requests are routed inside of AWS rather than over the public internet. Internally it creates an invoke event that has the same schema as an API Gateway proxy event.

Functionality of the Apollo Link Lambda

Features

✅  Support for @apollo/client 3.0+

✅  Fully compatible to HTTPLink

✅  Support for AWS API Gateway Events 1.0 & 2.0

Usage

npm i --save @dealmore/apollo-link-lambda   # npm or
yarn add @dealmore/apollo-link-lambda       # yarn

Please note that this package has peerDependencies to @apollo/client, aws-sdk and graphql. So you might need to install this packages too if they are not already installed.

import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client';
import { createLambdaLink } from '@dealmore/apollo-link-lambda';

const isServer = typeof window === 'undefined';

const client = new ApolloClient({
  ssrMode: isServer,
  link: isServer
    ? createLambdaLink({
        functionName: 'MyLambdaFunc',
      })
    : createHttpLink({
        uri:
          'https://psot142kj1.execute-api.eu-central-1.amazonaws.com/graphql',
      }),
  cache: new InMemoryCache(),
});

Options

OptionDefaultDescription
functionName(required)The name of the Lambda function.
Possible name formats:
  • Function name
  • Function ARN
  • Partial ARN
For examples refer to the AWS SDK documentation.
httpMethodPOSTSets the type of HTTP method for the invoke event.
Possible values:
  • POST
  • GET
payloadFormatVersion1.0Sets the payload format version.
Possible values:
  • 1.0
  • 2.0
headers{}You can add custom headers here that should be included in every request.
{  "key": "value"  }
lambdavoidAllows to pass in a pre configured Lambda instance.

AWS IAM Policy

To invoke the GraphQL Lambda function make sure that associated AWS account or the AWS role of the client has the permission for the lambda:InvokeFunction action:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "InvokeLambda",
      "Effect": "Allow",
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:*:*:function:MyLambdaFunc"
    }
  ]
}

License

MIT - see LICENSE for details.

FAQs

Last updated on 27 Aug 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc