sah-plugin
v1.0.0
Published
Serverless plugin for creating Lambda aliases and integrate with SAH project
Readme
SAH Plugin
A Serverless plugin to create AWS Lambda aliases without imposing a way-of-working with them.
This plugin is based in serverless-simple-alias, we only add support to other events apart from api gateway and specific functionalities to integrate with SAH
Motivation
This plugin assists with two use cases:
- Creating an "active" alias, and using that alias in API Gateway Event Sources and Event Rules.
Installation
npm install --save-dev sah-pluginAdd the plugin to serverless.yml:
plugins:
- sah-pluginNote: Node 10.x or higher runtime required.
Usage
Inside your Serverless config, include this plugin and define a custom.sah object and specify the activeAliasName
plugins:
- sah-plugin
...
custom:
sah:
activeAliasName: 'ACTIVE' # Default: 'ACTIVE'
useActiveAliasInEvents: true # Default: false. Whether to change API Gateway to target the active alias or not
makeLambdasActive: true # Default: false. Whether to apply the active alias to the lambdas that are being deployed now. Could vary per environment.
sahUrl: 'http://{app_url}/api/projects/{project_id}/deployments' # Default: null. It is not mandatory but you can use it if you wish to synchronize your displays with your SAH application.
sahToken: '1|fZH1G7lyRZZKcK4AD8PaaQlXlTeeM7bc2XdjOsqBeecfb75f' # Default: null. It is not mandatory but you can use it if you wish to synchronize your displays with your SAH application.In practice, different environments have different deployment requirements. For example, in production it may be preferable to not deploy the new versions of the Lambdas with the active tag.
How it works
This plugin changes the following generated AWS CloudFormation templates:
- Adds an
AWS::Lambda::Aliasresource for each alias, per function, and links each resource to the correspondingAWS::Function::Versionresource. - Changes the existing
AWS::ApiGatewayV2::Integrationresources (that haveProperty.IntegrationTypeofAWS_PROXY) to include the active-alias name in theProperty.IntegrationUri - Changes the existing
AWS::Lambda::EventSourceMappingresources to include the active-alias name in theProperty.FunctionName - Changes the existing
AWS::Events::Ruleresources to include the active-alias name in theProperty.Targets - Changes the existing
AWS::Lambda::Permissionresources to point theProperties.FunctionNameto theAWS::Lambda::Aliasresource.
