IniziaInizia gratis

Using environment variables

Environment variables are useful for storing variables that you may want to change without modifying code.

Cody is going on vacation. While she would normally be the main person to receive messages, for a week it will be have to go to Jeff.

Let's tweak the Lambda function a bit to send a personalized SMS to Jeff!

KWuRb.png

I have assigned Jeff's phone number and name to the relevant environment variables.

Questo esercizio fa parte del corso

Streaming Data with AWS Kinesis and Lambda

Visualizza il corso

Istruzioni dell'esercizio

  • Import the os module.
  • Get the environment variables for PHONE_NUMBER and RECEIVER.
  • Get the environment variable for DEPARTMENT, and if it's not set, fall back to 'Fleet Department'.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

import ____

# Get Environment variables, specify defaults
PHONE_NUMBER = os.____.get("ALERT_PHONE_NUMBER", None)
RECEIVER = os.environ.____("RECEIVER_NAME", "Random Person")
DEPARTMENT = ____("DEPARTMENT", "____")

# Construct message 
message = """Hello {} from {}!
Here are the speeders:
{}
""".format(RECEIVER, DEPARTMENT, speeders.to_string())

# Send message
sns.publish(PhoneNumber = PHONE_NUMBER, Message = message)
Modifica ed esegui il codice