You can make use of 'callback' when using the synchronous functions, when using async you should return a promise, like:
const AWS = require('aws-sdk');
exports.handler = async (event, context, callback) => {
const ec2 = new AWS.EC2({ region: event.instanceRegion });
return ec2.stopInstances({ InstanceIds: [event.instanceId] }).promise()
.then(() => `Successfully stopped ${event.instanceId}`)
.catch(err => console.log(err));
};
Actually here when you use 'async' you are returning nothing but "null" as a response so it will just terminate and the 'stop instance' will not finish its work.
Do Check out the AWS Certification Course offered by Intellipaat.
For learning more about AWS Lambda, do watch the video tutorial below: