serverless-aws-lambda
Advanced tools
Weekly downloads
Readme
AWS Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline Application Load Balancer and API Gateway lambda server mocking.
http
moduleyarn add -D serverless-aws-lambda
# or
npm install -D serverless-aws-lambda
service: myapp
frameworkVersion: "3"
configValidationMode: error
plugins:
- serverless-aws-lambda
Start the offline server
SLS_DEBUG="*" sls aws-lambda -s dev
It is also possible to passe port from the CLI with --port
or -p
.
This will overwrite serverless.yml custom > serverless-aws-lambda values if they are set.
Offline server supports Application Load Balancer and API Gateway endponts.
Appropriate event
object is sent to the handler based on your lambda declaration.
functions:
myAwsomeLambda:
handler: src/handlers/awsomeLambda.default
events:
- alb:
listenerArn: arn:aws:elasticloadbalancing:eu-west-3:170838072631:listener/app/myAlb/bf88e6ec8f3d91df/e653b73728d04626
priority: 939
conditions:
path: "/paradise"
method: GET
myAwsomeLambda
is available at http://localhost:PORT/paradise
However if your declare both alb
and http
or httpApi
inside a single lambda events
with the same path
you have to specify desired server by setting alb
or apg
inside your request's:
X-Mock-Type
.x_mock_type
.Please note that invoking a lambda from sls CLI (sls invoke local -f myFunction
) will not trigger the offline server. But you are still able to inject any event with -d 'someData'
sls CLI option.
You can also invoke your Lambdas with a custom event
object by making a POST request to:
http://localhost:3000/@invoke/myAwsomeLambda
for aws-sdk
Lambda client compatibility it is also possible to request to:
http://localhost:3000/2015-03-31/functions/myAwsomeLambda/invocations
Example with with aws-sdk
Lambda Client:
const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda");
const client = new LambdaClient({ region: "PARADISE", endpoint: "http://localhost:3000" });
const DryRun = "DryRun";
const Event = "Event";
const RequestResponse = "RequestResponse";
const cmd = new InvokeCommand({
FunctionName: "myAwsomeLambda",
InvocationType: RequestResponse,
Payload: Buffer.from(JSON.stringify({ foo: "bar" })),
});
client
.send(cmd)
.then((data) => {
data.Payload = new TextDecoder("utf-8").decode(data.Payload);
console.log(data);
})
.catch((error) => {
// 🥲
console.log("error", error);
});
Lambdas are executed in worker threads. Only variables declared in your serverless.yml
are injected into process.env
except IS_LOCAL
, LOCAL_PORT
and NODE_ENV
.
online
online: false
will omit the deployement of your Lambda.functions:
myAwsomeLambda:
handler: src/handlers/awsomeLambda.default
online: false
files
functions:
myAwsomeLambda:
handler: src/handlers/awsomeLambda.default
files:
- ./resources/some/file.png
- ./resources/anotherFile.pdf
virtualEnvs
To have more control over the plugin you can passe a config file via configPath
param in plugin options:
custom:
serverless-aws-lambda:
port: 3000
configPath: ./config.default
See defineConfig for advanced configuration.
FAQs
AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.
The npm package serverless-aws-lambda receives a total of 287 weekly downloads. As such, serverless-aws-lambda popularity was classified as not popular.
We found that serverless-aws-lambda demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.