Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
/ echo Public
forked from swinton/echo

A simple AWS Lambda function

License

Notifications You must be signed in to change notification settings

torstello/echo

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

echo

A simple AWS Lambda function.

Installation

  1. Sign up for AWS Lambda
  2. Install and configure the aws command-line client
  3. Create a lambda-default role
  4. Install the echo function

Sign up for AWS Lambda

Sign up for AWS here.

The Lambda free tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month.

Install and configure the aws command-line client

To install the aws command-line client use pip:

pip install awscli --upgrade --user

To configure aws, follow these quick configuration steps.

Once configured, you should see config and credentials files in ~/.aws.

Create a lambda-default role

The Lambda function will assume a role when executing and will be granted permissions based on the policies attached to this role.

At the very least, we need to create a basic execution role that grants write permissions to CloudWatch Logs. AWS provides one that we can use, arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole.

Use aws iam create-role and aws iam attach-role-policy to create the role and attach the desired policy as follows:

# Create the role
aws iam create-role \
    --role-name lambda-default \
    --assume-role-policy-document file://.aws/lambda-default-role-policy.json \
    --description "Lambda execution role"

# Attach the policy to the role just created
aws iam attach-role-policy \
    --role-name lambda-default \
    --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

Look up the role to confirm everything looks good, and make a note of the Arn returned:

aws iam get-role \
    --role-name lambda-default

Install the echo function

Generate a .zip of the source code in package.zip:

# Generate package.zip
zip package echo.py

Copy package.zip to an S3 bucket that you own:

# Copy package.zip to your S3 bucket
aws s3 cp package.zip s3://${YOUR_AWS_S3_BUCKET}/lambda/

Finally, create the function, remember to specify the Arn of your lambda-default role:

# Create your function
aws lambda create-function \
    --publish \
    --runtime python2.7 \
    --role ${YOUR_ARN_LAMBDA_DEFAULT_ROLE} \
    --handler echo.handler \
    --function-name echo \
    --code S3Bucket=${YOUR_AWS_S3_BUCKET},S3Key=lambda/package.zip

Usage

Invoke using aws lambda invoke:

# Invoke the function and save the output to output.txt
aws lambda invoke --function-name echo --payload '["hello", "world"]' output.txt

Review the output via:

cat output.txt

About

A simple AWS Lambda function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.