How to use EDI API as AWS Lambda

Article author
  • Updated

InHouse EDI API allows you to run EdiNation's EDI translation and validation API in your own cloud or on-prem environment(s).

This tutorial uses the example AWS Lambda that comes with the EdiNation Inhouse product to demonstrate how to publish EdiNation Inhouse API as an AWS Lambda and API Gateway in your own AWS account(s).

InHouse API for AWS on GitHub



To complete this tutorial, you'll need the following:

  • Visual Studio 2022, which supports .NET 6.0. 
  • AWS Toolkit for Visual Studio 2022.
  • If you don't have an AWS account, create a free AWS account before you begin.
  • Download Postman - it's an application to consume/test your API.
  • EDI test file(s) - the API supports X12, EDIFACT, EANCOM, HL7, NCPDP, VDA, and EDIGAS. If you don't have a test file, use one of ours - X12 HIPAA, X12, EDIFACT.


Create a stack in AWS

The example uses AWS CloudFormation.

Detailed tutorial on how to create an AWS CloudFormation stack in the CloudFormation console. For this tutorial, we created a stack named "edinationtest".

  1. Download EdiNation Inhouse, unzip it, and navigate to folder edifabric-api-aws/EdiFabric.Api.AWS.
  2. Log in to your AWS account, go to CloudFormation, and select to create a new stack.
  3. Choose to upload the template file, and select file serverless.template from the folder you navigated to in the first step.
  4. Then use the default suggestions for the other tabs and finally, Create the stack.


  5. The stack resources creation will fail because we haven't uploaded the code to an S3 bucket. Leave it as it is, we only need the stack for now.


Publish the AWS Lambda from Visual Studio

EdiFabric.Api.dll only works with the edition of EdiFabric.dll included in the solution. Do not install EdiFabric separately from NuGet!

  1. Navigate to folder edifabric-api-aws and open solution EdiFabric.Api.AWS.sln in Visual Studio 2022.
  2. Ensure the references to EdiFabric.dll and EdiFabric.Api.dll exist.
  3. Open file Configuration.cs and change ApiKey to the API key you received when subscribing to EdiNation InHouse (the existing one is for the free EdiNation plan).


  4. Rebuild the solution and ensure all package dependencies were installed correctly.


  5. Turn off Windows Real-time virus protection.

    Windows Defender mistakenly reports Microsoft.Extensions.DependencyInjection and EdiFabric as threats and blocks the deployment. Please note that there is absolutely no threat, and this is due to a bug in AWS Toolkit for Visual Studio. You can scan EdiFabric.dll in Virus Total or a similar site of your choice, before turning off Windows Defender Real-time protection.


  6. Right-click on the project name and select "Publish to AWS Lambda".


  7. Select the stack you created in the first step, create a new S3 bucket edinationtestbucket to publish to, and finally, click Publish.


  8. Once published, copy the URL:



Test the Function

  1. You can also find the URL in the AWS portal. Go to API Gateway and select "edinationtest":


  2. Then go to Dashboard and copy it:


  3. Download and open Postman. Let's test the X12 read operation first.
  4. Open a new tab in Postman, select the POST method and add the following request URL (full API reference):

    {Your API URL}/x12/read
  5. Go to the Body tab, select the "binary" content, and then browse to your text X12/HIPAA file.

    If you don't have a test file, use one of ours - X12 HIPAA, X12, EDIFACT.


  6. Finally, hit the Send button and inspect the response body:




If you receive an error message that begins with any of the below, then your API key wasn't correctly configured or has expired, or you've reached a quota limit:

  • One or more errors occurred. (Can't get token!)
  • Transaction set is not supported


Implement distributed cache

For every request to your API, at least two requests are initiated to the cloud EdiNation API - one to acquire a token and another to get the model for your transaction type (if your file contains transactions of different types, such as invoices and purchase orders, then there will be a separate request for each type).

To avoid making these requests, you can implement a distributed cache that can share tokens and models across function invocations. This example uses an AWS S3 bucket as a distributed cache.

Token cache

To implement the token cache, follow these steps:

  1. (Optional) Open the file Configuration.cs and change the bucket name and the object name for the token. By default, the example points to the same S3 bucket (edinationtestbucket) used for publishing the Lambda functions.


  2. Open the file EdiFunctions.cs and uncomment all lines that begin with:

  3. In the same file EdiFunctions.cs, comment out all lines that begin with:

    // SerialKey.Set
  4. Done! The next time you execute a Lambda function, the token will be loaded from the cache.

Models cache

Let's assume you will be working with files containing X12 transactions of version 4010. By default, every time you execute an operation of the InHouse API, the model for standard X12 and version 4010 is retrieved from the EdiNation API like this:


Using a cache will load all models from the cache instead of the EdiNation API.

To implement the models' cache, follow these steps:

  1. Go to EdiNation Formats and select the model you will be loading to the cache (in this example, X12 4010).


  2. Download the model as a .dll file.


  3. The file on your disk must be EdiNation.X12.ASC.004010.dll.
  4. Go to the AWS S3 bucket that you will use as a cache (in this example edinationtestbucket) and upload the file EdiNation.X12.ASC.004010.dll.


  5. Open the file EdiFunctions.cs and uncomment all lines that begin with:

  6. Done! The next time you execute a Lambda function for X12 4010, the models will be loaded from the cache.


Configure CORS

When you use the in-house edition of EDI Translator, you need to configure CORS in API Gateway.

In API Gateway Resources, select each analyze operation, and then Enable CORS from the Actions dropdown:


Uncheck POST and leave only OPTIONS. Then add Ocp-Apim-Subscription-Key to the list of allowed headers:


If the operation fails, edit the OPTIONS Method Response:


To add the following headers:


Then repeat Enable CORS from the Actions step.

Finally, deploy the changes:



Next steps

Learn about the in-house edition of EDI API.

Learn about how to use InHouse EDI API as Azure Function

How to use Inhouse EDI API as an ASP .NET Core application



Share this:

Was this article helpful?



Please sign in to leave a comment.