Giter VIP home page Giter VIP logo

serverless-feed-logger's Introduction

serverless-feed-logger

This is a simple AWS Lambda function that downloads a file from a given URL and stores logs it to the standard CloudWatch log used by the Lambda function. This is useful if you encounter some frequently changing data on the web, in a small textual format. For example, you may wish to keep snapshots of an XML or JSON feed, such as an ATOM feed from a blog or data from a realtime API. Using Lambda absolves you of having to keep a server on-line for this task. With the help of CloudWatch Events, your function can automatically run on a regular basis, either at a fixed rate (e.g. minutely, hourly, daily), or per a cron expression (e.g. every Sunday at 12:00, the first day of every month at midnight).

This tool is most suitable for small, text-based responses, where the benefits of being able to quickly filter and retrieve results via CloudWatch logs make sense. If the data you want to download is in the hundreds of kilobytes or larger, you are likely better off with my similar serverless-file-archiver app, which stores the downloaded data in an S3 bucket.

Deployment

Deploying this serverless app to your AWS account is quick and easy using AWS CloudFormation.

Packaging

With the AWS CLI installed, run the following command to upload the code to S3. You need to re-run this if you change the code in archiver.py. Be sure to set DEPLOYMENT_S3_BUCKET to a bucket you own; CloudFormation will copy the code function into a ZIP file in this S3 bucket, which can be deployed to AWS Lambda in the following steps.

DEPLOYMENT_S3_BUCKET="YOUR_S3_BUCKET"
aws cloudformation package --template-file cloudformation.yaml --s3-bucket $DEPLOYMENT_S3_BUCKET \
  --output-template-file cloudformation-packaged.yaml

Now you will have cloudformation-packaged.yaml, which contains the full path to the ZIP file created by the previous step.

Configuring

Next, let's set the required configuration. You can set the following parameters:

  • STACK_NAME is the name of the CloudFormation stack that you'll create to manage all the resources (Lambda functions, CloudWatch Events, S3 buckets, IAM policies) associated with this app. You can set this to a new value to create a new instance with different parameters in your account, or use the same value when re-running to update parameters of an existing deployment.
  • DOWNLOAD_URL is the web address whose contents you want logged.
  • SCHEDULE is a CloudWatch Event Schedule Expression at which to invoke this function.
STACK_NAME="serverless-feed-logger"
DOWNLOAD_URL="https://easweb.eas.ualberta.ca/weather_service.php?js"
SCHEDULE="rate(1 minute)"

With these configuration parameters defined, we can call cloudformation deploy to create the necessary resources in your AWS account:

aws cloudformation deploy --template-file cloudformation-packaged.yaml --capabilities CAPABILITY_IAM --parameter-overrides \
  "Schedule=$SCHEDULE" \
  "DownloadURL=$DOWNLOAD_URL" \
  --stack-name $STACK_NAME

If all went well, your stack has now been created. You can run the following to discover the name of the Log Group that will hold the Lambda's output, or go browse for it in the AWS Console.

aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs' --output text

serverless-feed-logger's People

Contributors

ranek avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.