GithubHelp home page GithubHelp logo

betht1220 / account-unarchived-function Goto Github PK

View Code? Open in Web Editor NEW

This project forked from event-stream-processing-microservices/account-unarchived-function

0.0 1.0 0.0 7 KB

License: Apache License 2.0

Shell 41.40% JavaScript 58.60%

account-unarchived-function's Introduction

Account Unarchived Function

Node.js source code and deployment scripts for an AWS Lambda function. This function is referenced in an Event Stream Processing Microservices example project as a git sub-module.

The lambda function is triggered from events sourced from the account-worker application. The lambda function uses an Amazon API Gateway trigger that is invoked from a Spring Cloud Stream application.

Function Details:

This lambda function responds to an AccountEvent that applies a state change to an Account resource.

  • context: accounts
  • function: account-unarchived
  • source_state: ACCOUNT_ARCHIVED
  • target_state: ACCOUNT_ACTIVE
  • event_type: ACCOUNT_ACTIVE
  • event_format: application/hal+json

Description:

This event handler is triggered in response to an Account resource transitioning from an ACCOUNT_ARCHIVED status to an ACCOUNT_ACTIVE status. The function confirms the target state of the Account API resource that is linked within the payload of the supplied AccountEvent resource.

This AWS lambda function is a backing service to the account-worker application. A service binding should inject the AWS Lambda resource address and credentials into the account-worker container as environment variables.

Account microservice

The lambda function uses a Node.js module named Traverson, which is a REST client implementation for HATEOAS. The reference architecture uses Spring HATEOAS to describe REST API resources with embedded links. The links embedded in each API resource allows the code in the lambda function to be completely stateless.

The lambda function only needs to import the Traverson dependency to interact with API resources managed by the account-web microservice.

// Lambda Function Handler (Node.js)
exports.handler = (event, context, callback) => {
  // Loads the traverson client module
  var traverson = require('traverson');

  // Apply the confirm command to the Account resource
  traverson
    .from(event._links.account.href)
    .follow('$._links.self.href',
      '$._links.commands.href',
      '$._links.confirm.href')
    .get(function(error, response) {
      // Return the account result
      callback(error, response);
    });
};

Deployment

A shell script is provided in ./deploy.sh. This script uses the AWS CLI to create a deployment package using an AWS CloudFormation Template defined in ./deployment.yaml. To deploy the lambda function, you must have the AWS CLI installed and configured to an IAM user with sufficient permissions to execute the script.

The script will create a deployment package for the lambda function and upload it as a zip file to an S3 bucket. The bucket name is an argument to the the deployment script.

account-unarchived-function's People

Contributors

kbastani avatar

Watchers

James Cloos 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.