Coder Social home page Coder Social logo

danmgs / aws.lambda.worker Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 250 KB

AWS Lambda Workflow deployed via a Cloud Formation template

C# 86.70% Batchfile 13.30%
aws dotnetcore aws-lambda lambda cloudformation aws-cloudformation s3 aws-sns sns elasticsearch x-ray cloudwatch dotnet csharp cloud sns-topic

aws.lambda.worker's Introduction

AWS . LAMBDA . WORKER

An AWS Lambda Worker that is triggered by SNS Topic in order to index message to an Elastic Search Service.

alt capture

alt capture

Build the lambda zip file and upload to S3

First, click on the file package.bat to generate AWS.Lambda.Worker.zip and upload it to the S3 bucket (must be global unique name). Here I chose mine, by instance:

com.aws.lambda.worker.cloudformation

alt capture

Deploy the setup to AWS

Deploy with the cloud formation template

You need to upload the template and fill the parameters directly in the AWS console.

lambda-xray.yaml

This template will :

  • retrieve the Lambda zip artifact to deploy it to AWS Lambda Service.
  • create the Lambda Role with CloudWatch + X-Ray + Elastic Service permissions.
  • create the SNS Topic.

Deploy with the bat file

First, you need to edit this bat file according to your region (see parameter --region) :

cloudformation/
  |
  |->aws-cli-deploy.bat

You need to configure the cloud formation parameters in the file :

cloudformation/
  |
  |->parameters.json

Customize with your own values :

  • your S3 bucket (must change to be global and unique name)
  • your elastic search service url
  • your SNS Topic
  • ..etc

alt capture

When clicking the bat file, these parameters will be passed to the cloud formation template.

Important note on the Lambda function timeout

As it takes like more than 10s the first time it is initializing the elastic search client (and indexing), the lambda function should be configured with a timeout of 15s minimum, otherwise it will not run and trace any logs in CloudWatch.

See parameter LambdaTimeoutParam in the cloud formation template.

Deploy solely the lambda worker artifact to AWS

This additionnal section details a way to upload the lambda worker manually.
This will not create the whole setup (create SNS topic, create Lambda Role ..etc).

Publish via Visual Studio

On the project, right click to publish:

alt capture

alt capture

Fill the options. Please note that these values will edit the file aws-lambda-tools-defaults.json accordingly.

alt capture

xxxaccountidxxx           -> will be your AWS account ID
xxxelasticserviceurlxxx   -> will be your elastic search service url (environment variable value)

Testing the application

Publish message in SNS

In order to trigger the lambda function, publish a message using the generated SNS topic, using the following json structure:

	{
		"Title": "Welcome message sample",
		"Content": "Hello world !"
	}

Checking the results

  • You can check logs in AWS CloudWatch.
  • You can trace and analyze with X-Ray.
  • You can check the message being indexed under Elastic Seach Service (using elastic queries and/or Kibana interface).

Details on the lambda function implementation

Please note the lambda function is implemented in dotnetcore2.1 as AWS manages this version.

In order to run, the lambda function ...

  • is triggered when a message is published to the SNS topic.
  • indexed the message to an elastic search service.
    The url of this service is passed as the environment variable "ESurl".
    When the environment variable is not existing, there is a fallback configuration (see file appsettings.json).
    But this is not recommended as it is not convenient to configured this way.

Useful links

aws.lambda.worker's People

Contributors

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