Alibaba Cloud Function Compute can create function based API endpoints.
To create HTTP endpoints as event sources for your Alibaba Cloud Function Compute, use the http
event syntax.
This setup specifies that the first
function should be run when someone accesses the Functions API endpoint via a GET
request. You can get the URL for the endpoint by running the serverless info
command after deploying your service.
Here's an example:
# serverless.yml
functions:
hello:
handler: index.hello
events:
- http:
path: /foo
method: get
// index.js
exports.hello = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({ message: 'Hello!' }),
};
callback(null, response);
};
Note: See the documentation about the function handlers to learn how your handler signature should look like to work with this type of event.
Product