Giter VIP home page Giter VIP logo

echo's Introduction

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

echo's People

Contributors

swinton avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.