@growsari/invoke-lambda
v1.0.4
Published
Utility function for calling microservices within the API and business logic layer
Downloads
452
Keywords
Readme
Invoke Lambda Package
Utility function for calling microservices within APIs.
Usage
const invokeLambda = require('@growsari/invoke-lambda')
await invokeLambda('ms-some-project', 'create', { name: 'some-name', description: 'some-value'})
You may specify the API version and the region as named parameters after params
. They will default to '2015-03-31'
and process.env.AWS_DEFAULT_REGION
respectively, if not defined.
Async
await invokeLambda('ms-some-project', 'create', { name: 'some-name', description: 'some-value'}, {async: true})
You can specify {async: true} to execute lambda asynchronously.
Details
Invokes the lambda named [service]-[stage]-[operation]
.
Assumptions
process.env.AWS_DEFAULT_REGION
is named in the project.process.env.IS_OFFLINE
istrue
when deployed.- When in offline mode, it is deployed through Docker deployment.
process.env[``${service.toUpperCase()}-PORT``]
is assigned to the deployment port of the specific service in the Docker deployment.- The containing lambda has access to all of the lambdas named.
- Called function response has the following payload format
{
data: Object,
success: Boolean,
message: String,
code: any
}
so that the response will be identified properly as a success or a failure.
Errors
| Code | Message | | --- | --- | | INVOKE-001 | Invalid lambda function 'function_name' | | INVOKE-002 | Error executing lambda 'function_name' |