serverless-apikey-output
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Serverless Api Key Output Plugin

npm license

A serverless plugin to store an API Key and it's value from your AWS CloudFormation Stack in a JSON file.

Warning!

Do not commit an API Key to your repo!

Usage

Install

$ npm install serverless-apikey-output
$ yarn add serverless-apikey-output

Configuration

plugins:
  - serverless-apikey-output

custom:
  output:
    keys: #optional: the default is to export all api keys
      - MyApiKeyName # this is the apikey "name" -- not to be confused with the cloudformation logicalId
    file: .build/stack.json # optional: the default path is '.serverless-apikey-output/${self:provider.stage}.keys.json'

Example

The plugin works by listing all resources of type "AWS::ApiGateway::ApiKey" after deployment, so it will pick up any created API Key.

Serverless.yml

service: apikey-example
provider:
  name: aws
  runtime: nodejs12.x
  apiKeys:
    - myapikey
    - ${self:provider.stage}-test-key

plugins:
  - serverless-apikey-output

functions:
  test:
    handler: handler.test
    events:
      - http:
          path: test
          method: get

custom:
  apiKeyOutput:
    keys:
      - ${self:provider.stage}-test-key # only export one of the two keys created
    file: test-keys/${self:provider.stage}.keys.json

Output Sample

[
    {
        "id": "<Physical APIKey Id>",
        "value": "<Api Key Value>",
        "name": "dev-test-key",
        "enabled": true,
        "createdDate": "2020-09-15T07:24:38.000Z",
        "lastUpdatedDate": "2020-09-15T07:24:38.000Z",
        "stageKeys": [
            "<ApiGatewayId>/dev"
        ],
        "tags": {
            "STAGE": "dev"
        }
    }
]

Readme

Keywords

none

Package Sidebar

Install

npm i serverless-apikey-output

Weekly Downloads

41

Version

0.1.0

License

MIT

Unpacked Size

26.5 kB

Total Files

12

Last publish

Collaborators

  • tomaiandrew