This tutorial documents how to use a command line to define and invoke an AWS Lambda function. Invocation will be via unsigned synchronous requests using two types of API Gateways: HTTP and REST. The reason for not requiring a request to be signed is so the API is publicly accessible. This means no security credentials are necessary to invoke the Lambda functions behind their API Gateways.
These instructions also detail how to create a short Python Lambda function that merely echoes its parameters, but you can substitute your own Lambda function if you modify the parameters passed to it appropriately.
The same Lambda function is invoked via two mechanisms (HTTP and REST), using the same data. The initial steps are the same for both mechanisms. Subsequent steps are explained separately.
If you want to type along:
-
Configure AWS CLI:
$ aws configure
The dialog looks like the following. This tutorial needs the default output format to be JSON:
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: json
-
Examine the file called
setEnvVars
and make any changes you like for this tutorial's environment variables that are indicated as being modifiable. -
Read the environment variables defined in
setEnvVars
into your shell environment by using the bashsource
command.$ source setEnvVars
The pages that follow provide values for some of the environment variables.
When a value changes the setEnvVars
will need to be re-sourced.
This tutorial provides 3 bash scripts: capture
, extract
and updateEnvVar
.
- The
capture
script runs commands and savesstdout
to a hidden file called.result.json
in this directory. - The
extract
script assumes that.result.json
contains JSON and extracts a value from it usingjq
. The value is written toSTDOUT
. if an optional second argument is provided it is assumed to be the name of an environment variable and its value is updated insetEnvVars
. Each time a value is changed insetEnvVars
that file needs to be re-sourced. - The
updateEnvVar
script creates or updates environment variable definitions insetEnvVars
.
Continue on to Create an AWS Lambda Function.
I would like to thank Raju J. of Amazon Web Services for his kind and thoughtful input.