Skip to content

event-stream-processing-microservices/account-unsuspended-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Account Unsuspended 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-unsuspended
  • source_state: ACCOUNT_SUSPENDED
  • 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_SUSPENDED 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published