Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I am using the aws-node template. I want to do something like this:

sls deploy URL=''

Where URL is the environment variable. I am trying to pass this env variable to my serverless.yml


  name: aws

  runtime: nodejs8.10

  stage: dev

  region: us-west-2


    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")


    process.env.URL // Accessing the environment variable.

  ).then(function (response) {

      console.log(`Status: ${response.status}`)


    .catch(function (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.

1 Answer

0 votes
by (44.4k points)
edited by

Pass URL as an environment variable and not as an argument within it.

Do something like this:

$ URL='' sls deploy

This will not work:

$ sls deploy URL=''

Need help mastering AWS Lambda and other AWS skills? Go through AWS Training Page and become an AWS expert! 

Browse Categories