Serverless Plugin
This is a beta feature of Swarmion.
Installation
# using pnpm
pnpm add --save-dev @swarmion/serverless-plugin
# using yarn
yarn add --save-dev @swarmion/serverless-plugin
# using npm
npm install --save-dev @swarmion/serverless-plugin
Then in your serverless.ts
files, add @swarmion/serverless-plugin
to the list of your plugins.
Configuration
Add a contracts
key to your Serverless file:
import { myFirstContract, mySecondContract } from 'my-contracts-package';
import { consumedContract } from 'other-contracts';
const serverlessConfiguration = {
service: 'my-app',
provider: {
name: aws
},
plugins: ['@swarmion/serverless-plugin'],
functions: {
...
},
contracts: {
provides: {
myFirstContract,
mySecondContract,
},
consumes: {
consumedContract,
},
},
}
Where all the contracts are defined using serverless-contracts.
Commands
serverless localContracts
: prints the local version of the contractsserverless remoteContracts
: prints the currently deployed version of the contractsserverless safeDeploy --strategy <strategy>
: a wrapper around thedeploy
command of the Serverless Framework, check if the contracts modification is deployable with the chosen strategy. Choices arePROVIDER_FIRST
orCONSUMER_FIRST
serverless generateOpenApiDocumentation
: prints an OpenApi documentation of your ApiGateway contracts in the provides section of the serverless configuration
Typing
This plugin exposes its own types. In order to properly type your Serverless service file:
import { ServerlessContracts } from '@swarmion/serverless-plugin';
import { AWS } from '@serverless/typescript';
const serverlessConfiguration: AWS & ServerlessContracts = {
...
}