Socket
Book a DemoInstallSign in
Socket

esanuka

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esanuka

esanuka is manage idempotency tool for AWS API Gateway.

0.9.0
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

esanuka

esanuka is manage idempotency tool for AWS API Gateway.

Installation

You can install via npm:

npm install esanuka -D

Or yarn:

yarn add esanuka -D

Account Specification

Need to set environment variables of AWS account:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_ACCOUNT_ID

Make sure account has APIGateway and Lambda policies.

Resource Definition

esanuka accepts following YAML structure:

authorizers:
  authorizer-function-name:
    type: lambda
    function: authorizer-lambda-function
    sourceHeader: cookie
    ttl: 300

resources:
  - path: /path/to/endpoint
    description: Endpoint description
    methods:
      GET:
        integrationType: lambda
        function: dispatch-lambda-function
  ...

Parameters specifications are:

nametyperequireddescription
authorizersObjectNoAuthorizer specifications. Key is authorizer name
authorizers[key].typeStringYesAuthorizer Type. Currentry support lamba only
authorizers[key].functionStringYesLambda function name
authorizers[key].sourceHeaderStringNoAuthorize identity source from header name. Either sourceHeader or sourceQuery is required
authorizers[key].sourceQueryStringNoAuthorize identity source from querystring. Either sourceHeader or sourceQuery is required
authorizers[key].ttlNumberNoTTL of authentication cache
resourcesArrayYesResource specifications
resources[].pathStringYesEndpoint path
resources[].descriptionStringYesEndpoint description
resources[].methodsObjectYesEndpoint method specifications. Key is method name
resources[].methods[method].integrationTypeStringYesBackend integration type. Value must be one of lambda, http, and vpc
resources[].methods[method].functionStringNoLambda function name. This is required if integrationType is lambda
resources[].methods[method].urlStringNoHTTP proxy URL. This is required if integrationType is http
resources[].methods[method].vpcLinkIdStringNoVPC Link Id. This is required if integrationType is vpc
resources[].methods[method].serviceNameStringNoBackend service name. This is used for VPC link to host
resources[].methods[method].pathsObjectNoEndpoint path paramter specifications. e.g If endpoint is /path/to/{id}, paths must specify as id: true
resources[].methods[method].queryStringsObjectNoEndpoint query string specifications. e.g If endpoint accepts /path/to?id=[id], queryStrings must specify as id: true
resources[].methods[method].authorizerTypeStringNoAuthorizer type. Value is one of CUSTOM of AWS_IAM
resources[].methods[method].authorizerStringNoAuthorizer name. This is required if authorizerType is CUSTOM
resources[].methods[method].responsesObjectYesMethod/Integration response specifications
resources[].methods[method].responses[status].headersObjectNoSending HTTP headers to client
resources[].methods[method].responses[status].patternObjectNoMapping status code pattern

Example is below:

Lambda Integration

Lambda integration always set as Lambda Proxy Integration

resources:
  - path: /path/to/endpoint
    description: Endpoint description
    methods:
      GET:
        integrationType: lambda
        function: dispatch-lambda-function

In Lambda integration, status code and http headers are passthrough between the request/response.

VPC Integration

Request can proxy using VPC Link. The usage of this is backend origins put in private VPC network.

resources:
  - path: /path/to/endpoint/{id}
    description: Endpoint description
    methods:
      GET:
        integrationType: vpc
        vpcLinkId: [vpc link id]
        serviceName: example.ap-northeast-1.elasticbeanstalk.com
        paths:
          id: true
        responses:
          200:
            headers:
              Access-Control-Allow-Origin: false

On above case, API Gateway will proxy to http://example.ap-northeast-1.elasticbeanstalk.com/path/to/endpoint/{id} using with VPC Link. And path contains {id}, bind paramter, so you need to define paths section.

In addition, you can transform dispatch path with backendPath paramter:

resources:
  - path: /path/to/endpoint/{id}
    description: Endpoint description
    methods:
      GET:
        integrationType: vpc
        vpcLinkId: [vpc link id]
        backendPath: /endpoint/{id} ## add this line
        serviceName: example.ap-northeast-1.elasticbeanstalk.com
        paths:
          id: true
        responses:
          200:
            headers:
              Access-Control-Allow-Origin: false

Then API Gateway will proxy to http://example.ap-northeast-1.elasticbeanstalk.com/endpoint/{id} using with VPC Link.

HTTP Integration

Simply HTTP proxy.

resources:
  - path: /proxies/{proxy+}
    description: Endpoint description
    methods:
      GET:
        integrationType: http
        url: https://example.com/proxies/{proxy}

API Gateway simply do proxy under /proxies/* requests to https://example.com/proxies/*.

Dry Run

esanuka supports dry-run, which compares between local and remote definitons, and display resource create/modify/delete plans to output. So you can confirm before deploy resources.

Binding Parameters

You can use binding paramteres in definition YAML file in ${} blaced:

resources:
  - path: /path/to/endpoint/{id}
    description: Endpoint description
    methods:
      GET:
        integrationType: vpc
        vpcLinkId: ${VPC_LINK_ID}
        backendPath: /endpoint/{id} ## add this line
        serviceName: example.ap-northeast-1.elasticbeanstalk.com
        paths:
          id: true
        responses:
          200:
            headers:
              Access-Control-Allow-Origin: false

Then, ${VPC_LINK_ID} will be replaced to environmen t variable.

Deployment with CLI

Easiest way is run from command line:

easnuka -f [defitnition YAML file] -s prod --rest-api-id=[rest api id]

With dry-run:

easnuka -f [defitnition YAML file] -s prod --rest-api-id=[rest api id] --dry-run

Deployment with programable

esanuka also can deploy with programably.

const esanuka = require('easnuka');
const defitnitions = esanuka.factory('/path/to/definition.yml', {});
esanuka(definitions, {
  restApiId: '[rest api id]',
  deploymentStage: 'prod'
});

With dry-run:

const esanuka = require('easnuka');
const defitnitions = esanuka.factory('/path/to/definition.yml', {});
esanuka.dryRun(definitions, {
  restApiId: '[rest api id]',
  deploymentStage: 'prod'
})l;

In addition, progoramable deployment has more garantees using options of second arguments:

const esanuka = require('easnuka');
const defitnitions = esanuka.factory('/path/to/definition.yml', {});
esanuka.dryRun(definitions, {
  onIntegrationParameters: Function,
  onMethodRequestParameters: Function,
  useLambdaWithStage: Boolean,
  lambdaAliases: Array<String>,
  baseDomain: String,
  restApiId: String,
  deploymentStage: String,
  verbose: Boolean,
  skipFunctionExistence: Boolean
});

Describes option fields with following:

nametyperequireddescription
onIntegrationParametersFunction(obj) => objNoHook on create integration request parameters. You can add more integration headers in this function
onMethodRequestParametersFunction(obj) => objNoHook on create method request parameters. You can add more integration headers in this function
useLambdaWithStageBooleanNoIf true, create Lambda integration with staging environment as ${environment.stage} function alias
lambdaAliasesArray of aliaesNoAdditional lambda function aliases. esanuka add lambda permissions automatically.
baseDomainStringNoAdditional base domain
restApiIdStringYesAPIGateway REST API ID
deploymentStageStringYesDeployment target stage name
verboseBooleanNoVerbose process logs
skipFunctionExistenceBooleanNoIf true, validation skips check of lambda function existence, it's useful for local development

Author

Yoshiaki Sugimoto

License

MIT

FAQs

Package last updated on 04 Jul 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.