简体   繁体   中英

Is it possible to push test events to AWS Lambda with the Serverless Framework?

I'm using the Serverless Framework to push to AWS Lambda. To test my functions, I'm currently just using the Lambda console to add each method, which is getting rather tedious, and I would like to have a way to push them along side with the code with serverless deploy .

在此输入图像描述

I've found this reference on the Serverless method for testing locally, but it doesn't seem to deploy those test events to Lambda.

Ideally, I'd like to be able to to do this in Serverless, but if there a way to do it via aws-cli it might be a good option too.

Unfortunately the test events are a feature of the AWS console alone, and are not made available on the AWS API (docs) .

As you've noticed, the Serverless Framework includes invocation commands- you've linked to Invoke Local, but Invoke also exists, which invokes your function, on the cloud, just like the AWS console.

As Serverless' Invoke command can take a JSON file as an event, a work around I might suggest is to create a folder (like tests/payloads ) of JSONs events as part of your code. That way you can then use serverless invoke -f functionName -p ./tests/payloads/payloadName.json to emulate the experience the AWS Console gives you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM