High-level Architecture

Scalable Salesforce Integrations on a Shoestring Budget – Step-by-Step Guide

AWS Lambda

Create the wrapper application

Open Eclipse IDE with Amazon SDK installed and create a new Maven project.

To be sure you’ve got all required dependencies, modify your pom.xml like the one below:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">






Adjust the Java Build Path to add all relevant External JARs (i.e. the executable JAR produced by Talend and all its dependencies from the lib folder in the same zip file) :

Here’s the main java class for the Account job, you can easily adjust it for Contact by adjusting lines 16 and 35:

package com.amazonaws.lambda.cardax.salesforce;

import java.util.LinkedList;
import java.util.Map;
import com.google.gson.Gson;

/* Import Amazon libraries for the relevant event that will trigger the Lambda, 
 * in this case SQS
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;

/* This is the executable JAR generated by Talend, import everything in it */
import local_project.aws_lambda_sfdc_account_df19_0_2.*;

public class SFDCIntegrationAccount implements RequestHandler<SQSEvent, String> {

	public String handleRequest(SQSEvent input, Context context) {
		try {
			 * Setting Defaults for Environmental Variables
			Map<String,String> env = System.getenv();
			final String TalendContext = env.get("TalendContext")==null || env.get("TalendContext").isEmpty() ? "DF19" : env.get("TalendContext");
			final String DBSCHEMA = env.get("DBSCHEMA")==null || env.get("DBSCHEMA").isEmpty() ? "public" : env.get("DBSCHEMA");

			 * Loop through SQS messages received from the Queue
			for(SQSMessage msg : input.getRecords()){
				final AWS_Lambda_SFDC_Account_DF19 talendJob = new AWS_Lambda_SFDC_Account_DF19();
				context.getLogger().log("*********** MESSAGE FROM SQS ***********");
				String body = msg.getBody();
				body = cleanupBody(body);

				LinkedList<String> argsList = new LinkedList<String>();
				argsList.add("--context_param AWS_SQSmessage=" +body);
				/** You can override Context variables taking them from System Env, 
				 * otherwise the values defined in Talend will be used 
				if(!DBSCHEMA.isEmpty()) argsList.add("--context_param DBSCHEMA=" +DBSCHEMA);
				String[] args = argsList.toArray(new String[argsList.size()]);

				/* Once we have our arguments we can run the Talend job with a single line of code */    	            	        
				String[][] bufferOutput = talendJob.runJob(args);

				/* The job output can be sent to CloudWatch Log for further analysis */
				Gson gson = new Gson();
				String bufferIn = gson.toJson(bufferOutput);
		} catch (Exception e) {
		return "OK";

	 * Removing carriage returns and other unneeded characters before passing it to Talend
	private String cleanupBody(String body) {
		body = body.substring(1, body.length()-1);
		body = body.replaceAll("\\n", "");
		body = body.replaceAll("\\r", "");
		body = body.replace("\n","");
		body = body.replace("\\n","");
		body = body.replace("\\r","");
		body = body.replace("\\", "");
		return body;


Adjust the Lambda function settings

Your code can now be packaged and uploaded as an AWS Lambda function using the AWS Toolkit for Eclipse. Right-click in your code, select AWS Lambda > Upload function to AWS Lambda… , and follow the instructions:

You will now see your Lambda function in the AWS Console, you can adjust the allocated memory, environment variables, etc.

Add a trigger for the lambda function

We can now link the Lambda function with its relevant SQS queue by clicking “+ Add Trigger“:

As soon as the Lambda function is added as trigger to the relevant SQS queue, the queued messages will be processed in batches of the size you specified [1 to 10 messages].

Test the integration

Create a record in Salesforce and verify that it is correctly inserted into the DB.
In case of issues, look for error messages on CloudWatch Logs

AWS CloudWatch

As per AWS description:

CloudWatch collects monitoring and operational data in the form of logs, metrics, and events, and visualizes it using automated dashboards so you can get a unified view of your AWS resources, applications, and services that run in AWS and on-premises. You can correlate your metrics and logs to better understand the health and performance of your resources. You can also create alarms based on metric value thresholds you specify, or that can watch for anomalous metric behavior based on machine learning algorithms. To take action quickly, you can set up automated actions to notify you if an alarm is triggered and automatically start auto scaling, for example, to help reduce mean-time-to-resolution. You can also dive deep and analyze your metrics, logs, and traces, to better understand how to improve application performance.

How Amazon CloudWatch works

Follow the excellent tutorials to get started on CloudWatch on AWS: https://aws.amazon.com/cloudwatch/getting-started/


I hope you will find this tutorial useful.
Feel free to share your feedback or enhancements to this AWS architecture using the comments below.
I’m not an AWS expert and I’m always looking forward to learning new skills.
For example, I believe there is an easier way to reproduce this configuration using AWS CloudFormation. It is a service to describe and recreate the whole architecture setup using JSON or YAML files. If you have experience with that service, please let me know if my assumption is correct. 🙂

Pages: 1 2 3 4 5



, ,




Leave a Comment