Perform the following steps:
- Let's create a simple serverless service with the following command. Two files will be created named handler.js and serverless.yml:
$ serverless create --template aws-nodejs --path my-canary-deployment
- Now replace the content of serverless.yml with the following code. Make sure that it is indented properly. We are creating a service with a function and an API gateway:
service: my-canary-deployment
provider:
name: aws
runtime: nodejs6.10
plugins:
- serverless-plugin-canary-deployments
functions:
hello:
handler: handler.hello
events:
- http: get hello
- Let's replace the content of handler.js with the following content:
module.exports.hello = (event, context, callback) => {
const response = {
statusCode: 200,
body: 'Go Serverless v1.0! Your function executed successfully!'
};
callback(null, response);
};
- Create a package.json file, as shown in the following code:
{
"name": "my-canary-deployment",
"version": "1.0.0",
"description": "",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "shashikant bangera",
"devDependencies": {
"serverless-plugin-aws-alerts": "^1.2.4",
"serverless-plugin-canary-deployments": "^0.4.0"
}
}
- Let's deploy this function to the AWS, as shown in the following code. Make sure that you have configured your AWS access and secret key before deploying:
$ npm install
$ serverless deploy -v
- Once successfully deployed, let's invoke the function and let it verify the execution. We will be provided with the service endpoint, so let's invoke the function with the endpoint, as shown in the following code:
$ curl https://<my-service-endpoint>-east-1.amazonaws.com/dev/hello
Go Serverless v1.0! Your function executed successfully!