Skip to content

Instantly share code, notes, and snippets.

@psenger
Last active November 20, 2023 04:15
Show Gist options
  • Select an option

  • Save psenger/b500c9058e35b8a36b7ded67b8143460 to your computer and use it in GitHub Desktop.

Select an option

Save psenger/b500c9058e35b8a36b7ded67b8143460 to your computer and use it in GitHub Desktop.
[LocaStack Cheat Sheet] #LocaStack #AWS

Localstack Cheat Sheet

Environment

I put everything in us-east-1 so this might not be for you.

export AWS_ACCESS_KEY_ID="test"
export AWS_SECRET_ACCESS_KEY="test"
export AWS_DEFAULT_REGION="us-east-1"

S3

REFERENCES:

  • <bucket-name> = bucket name
  • <item> = item to upload
  • <lambda-name> = the name of the lambada

Create S3 Bucket

awslocal s3api create-bucket --bucket <bucket-name> --region us-east-1

List S3 All Buckets

awslocal s3api list-buckets

Upload Item to S3 Bucket

awslocal s3api put-object \
  --bucket <bucket-name> \
  --key <item> \
  --body image.jpg

List items in a S3 Bucket

awslocal s3api list-objects \
  --bucket <bucket-name>

Cloudformation

List all cloudformations in all regions

#!/usr/bin/env bash
( awslocal ec2 describe-regions | jq -r '.Regions[].RegionName' ) | while IFS= read -r line
do
 awslocal cloudformation describe-stacks --region $line
done

Lambda

List all the versions of a Lambda

[!note] if you published versions

awslocal lambda list-versions-by-function --function-name <lambda-name>  --query 'Versions[*][Version, FunctionArn]' --output json

Execute a Lambda w/o api gateway

base64 -i input.json -o input.txt
awslocal lambda invoke --function-name my-function --payload file://input.txt outputfile.txt

In this command:

  • base64 encode the JSON file to a text file.
  • my-function is the name of your Lambda function.
  • file://input.json is the path to the JSON file that contains the payload to be passed to the Lambda function.
  • outputfile.txt is the file where the output of the Lambda function will be stored.

The input.json file might look like this:

{
   "key1": "value1",
   "key2": "value2",
   "key3": "value3"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment