Skip to main content

Command Palette

Search for a command to run...

Cheat Sheet #day19 - AWS Lambda Commands

Published
3 min readView as Markdown
Cheat Sheet #day19 - AWS Lambda Commands

AWS Lambda Commands Cheat Sheet

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. Below is a cheat sheet of common AWS Lambda commands using the AWS CLI (Command Line Interface).

Setup

  • Configure AWS CLI

      aws configure
    

    This command will prompt you to enter your AWS Access Key, Secret Key, region, and output format.

Function Operations

  • Create a Lambda Function

      aws lambda create-function \
        --function-name my-function \
        --runtime python3.8 \
        --role arn:aws:iam::123456789012:role/execution_role \
        --handler lambda_function.lambda_handler \
        --zip-file fileb://function.zip
    
  • Update a Lambda Function's Code

      aws lambda update-function-code \
        --function-name my-function \
        --zip-file fileb://function.zip
    
  • Update a Lambda Function's Configuration

      aws lambda update-function-configuration \
        --function-name my-function \
        --handler new_handler \
        --memory-size 256 \
        --timeout 60
    
  • Delete a Lambda Function

      aws lambda delete-function \
        --function-name my-function
    

Listing and Describing Functions

  • List Lambda Functions

      aws lambda list-functions
    
  • Get a Lambda Function's Configuration

      aws lambda get-function-configuration \
        --function-name my-function
    
  • Get a Lambda Function

      aws lambda get-function \
        --function-name my-function
    

Invoking Functions

  • Invoke a Lambda Function

      aws lambda invoke \
        --function-name my-function \
        --payload '{"key1": "value1"}' \
        response.json
    

Permissions and Policies

  • Add Permissions to a Lambda Function

      aws lambda add-permission \
        --function-name my-function \
        --statement-id some-id \
        --action lambda:InvokeFunction \
        --principal s3.amazonaws.com \
        --source-arn arn:aws:s3:::my-bucket
    
  • Remove Permissions from a Lambda Function

      aws lambda remove-permission \
        --function-name my-function \
        --statement-id some-id
    

Environment Variables

  • Update Environment Variables for a Function

      aws lambda update-function-configuration \
        --function-name my-function \
        --environment Variables={KEY1=value1,KEY2=value2}
    

Versions and Aliases

  • Publish a New Version of a Lambda Function

      aws lambda publish-version \
        --function-name my-function
    
  • Create an Alias for a Lambda Function Version

      aws lambda create-alias \
        --function-name my-function \
        --name my-alias \
        --function-version 1
    
  • Update an Alias

      aws lambda update-alias \
        --function-name my-function \
        --name my-alias \
        --function-version 2
    
  • Delete an Alias

      aws lambda delete-alias \
        --function-name my-function \
        --name my-alias
    

Event Source Mappings

  • Create an Event Source Mapping

      aws lambda create-event-source-mapping \
        --function-name my-function \
        --batch-size 100 \
        --event-source-arn arn:aws:sqs:us-west-2:123456789012:my-queue
    
  • Update an Event Source Mapping

      aws lambda update-event-source-mapping \
        --uuid 1234abcd-12ab-34cd-56ef-1234567890ab \
        --batch-size 200
    
  • Delete an Event Source Mapping

      aws lambda delete-event-source-mapping \
        --uuid 1234abcd-12ab-34cd-56ef-1234567890ab
    

Useful Options

  • Specify a Region

      aws lambda list-functions --region us-west-2
    
  • Profile Option

      aws lambda list-functions --profile myprofile
    

This cheat sheet provides a quick reference to the most commonly used AWS Lambda commands. For more detailed information and additional commands, refer to the official AWS CLI documentation.