Deploy Lambda Function

At some point during your local lambda development journey, you may decide to deploy the lambda function. Below you can find how to do it.

Open VSCode Terminal

Create a new terminal by pressing control + shift + `.

Activate Virtual Environment

$ source .venv/bin/activate

Set Environment Variables

In the terminal screen activate the virtualenv and set environment variables.

(.venv)$ PROJECTNAME=projectOne
(.venv)$ FUNCTIONNAME=functionOne
(.venv)$ BUCKETNAME=ozlambdabucket
(.venv)$ PROFILENAME=lambdadev
(.venv)$ STACKNAME=$FUNCTIONNAME-cfn

Configure AWS CLI Credentials

You need an IAM user in order to proceed. (AWS document on creating IAM userarrow-up-right)

(.venv)$ aws configure --profile $PROFILENAME
AWS Access Key ID [None]: AKIAQ4QLF5QD6GY8NKHW
AWS Secret Access Key [None]: T1A6BYuMGo4i84JO6bDYPcXAh+N1OvvemH0tb3Qa
Default region name [None]: us-east-1
Default output format [None]: json

Configure S3 Bucket

We need an S3 bucket to store packaged lambda code. Find a bucket name that is not already taken. Below we are using ozlambdabucket.

Modify SAM Configuration

Change template.yaml to look like below, with Outputs section.

Build and Package

Be sure you are under function folder.

Deploy

You will see an output similar to this one;

Test Your Stack

You will see an output similar to this one;

Get the Lambda Function ARN from the output of the previous command and invoke it using AWS CLI.

Last updated