Search code examples
amazon-web-servicesaws-lambdaserverless

How to detect if a Serverless Framework function is running offline with serverless-offline?


I am using python, and want to configure the database connection based on whether the function is running offline or deployed to AWS.

Some examples use the environment variable 'IS_OFFLINE', but it doesn't seem to be set.

Was that feature replaced with something else, or only available in the js runtime? What's the right way to detect whether a function is being run offline?


Solution

  • Try:

    console.log(process.env.IS_OFFLINE)
    

    https://www.serverless.com/plugins/serverless-offline#the-processenvis_offline-variable

    For Python:

    How to get environment from a subprocess?