liveBook · Manning

Environment variable

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

An environment variable is a named key-value setting made available to a running process through its execution environment.

An environment variable is a named key-value setting passed to a running process. In AWS Lambda, it lets function code read configuration without embedding each setting directly in the code. section 6.2.1

Configure a Lambda function with settings that the function reads during execution:

  • Set site to the URL that the health check should monitor. section 6.2.1
  • Set expected to the text snippet that must appear on the website. section 6.2.1
  • Read the variables from the function code while Lambda executes the health check. section 6.2.1

Changing a health-check setting

A website health check can use expected=cloudonaut when the website contains that word. Changing the value to FAILURE makes the check fail when the website does not contain FAILURE, allowing the failure to reach CloudWatch monitoring and email notification. section 6.2.1 section 6.2.3

SITE = os.environment['site']
 EXPECTED = os.environment['expected']

The code listing shows the function retrieving the SITE and EXPECTED settings from its environment. section 6.2.1

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Defines key-value settings, shows Lambda runtime access, and demonstrates changing a value to trigger a failed check.
Examples
Uses site and expected settings for a scheduled website health check, then changes expected to FAILURE to test monitoring.
What you can do after
Apply it via AWS Lambda to configure a health check and test its failure-monitoring path without changing the function logic.
How it connects
Connects environment variables with AWS Lambda, CloudWatch alarms, EventBridge schedules, and SNS notifications.

Also explained in

Compare how 19 books explain environment variable →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.