I am using the aws-node template. I want to do something like this:
sls deploy URL='https://postman-echo.com/post'
Where URL is the environment variable. I am trying to pass this env variable to my serverless.yml
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-west-2
environment:
URL: ${env:URL}
Then access it in my handler.js
const axios = require('axios');
module.exports.hello = async (event, context) => {
console.log("Lambda invoked\n")
await axios.post(
process.env.URL // Accessing the environment variable.
).then(function (response) {
console.log(`Status: ${response.status}`)
})
.catch(function (error) {
console.log(`Error`)
console.error(error);
});
return {
statusCode: 200,
body: JSON.stringify({
message: 'Function executed successfully!',
input: event
}),
};
};
I suspect that the issue is in how I am passing the environment variable to the program but my research has been to no avail.