Documentation

How to use EDI API as AWS Lambda

Article author
Admin
  • 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

 

Prerequisites

To complete this tutorial you'll need the following:

  • EdiNation Inhouse subscription - this contains the in-house EDI API installation files EdiFabric.dll and EdiFabric.Api.dll, and an example Visual Studion 2022 solution that implements an AWS Lambda.
  • 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".

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

createlambda1.png

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

 

Configure Auth API URL

You don't need to do anything in this step.

The Auth API sits in EdiNation's cloud and is called directly from EdiFabric.Api.dll in the following cases:

  • To authenticate the instance of the Inhouse API - this is an HTTP GET request to https://api.edination.com/v2/auth, which retrieves an authentication token. This token is valid for 30 days, and the next authentication request will be executed 3 days before the current token expires.
  • To retrieve the EDI models - this is an HTTP GET request to https://api.edination.com/v2/models/{id} , which retrieves the selected model. Once retrieved models are loaded in the .NET app domain and remain there until the app domain is unloaded (due to application restart/redeploy/scaling up/down).

The URL to the Auth API is configured as an environment variable in each of the Lambda functions. These are created automatically when publishing the solution from Visual Studio.

The environment variable is defined as:

Name Value
EDINATION_AUTHAPI_URL https://api.edination.com/v2

It is set in the serverless.template like this:

"Environment": {
	"Variables": {
		"EDINATION_AUTHAPI_URL": "https://api.edination.com/v2"
	}
},

 

Publish the AWS Lambda from Visual Studio

This edition of EdiFabric.dll can only be used with EdiFabric.Api.dll and not on its own. NuGet packages are also supplied in case you prefer to install local packages instead of referencing dlls.

  • Navigate to folder edifabric-api-aws and open solution EdiFabric.Api.AWS.sln in Visual Studio 2022.
  • Ensure the references to EdiFabric.dll and EdiFabric.Api.dll exist.
  • Rebuild the solution and ensure all package dependencies were installed correctly.

createlambda2.png

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

createlambda3.png

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

createlambda2.png

Sometimes Windows Defender reports EdiFabric.dll as a threat 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 also scan EdiFabric.dll in Virus Total or a similar site of your choice, before turning off Windows Defender Real-time protection.

  • Once published, copy the URL:

createlambda3.png

 

Test the Function

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

createlambda4.png

  • Then go to Dashboard and copy it:

createlambda5.png

  • Download and open Postman. Let's test the X12 read operation first.
  • Open a new tab in Postman, select the POST method and add the following request URL (full API reference Swagger/Docs):
{Your API URL}/x12/read
  • Go to the Headers tab and add the API key you received when subscribing to EdiNation InHouse API:
Header Key Header Value
Ocp-Apim-Subscription-Key Your API key

createlambda6.png

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

createlambda7.png

  •  Finally, hit the Send button and inspect the response body:

createazurefunction7.png

 

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:

aws-cors.png

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

aws-cors2.png

If the operation fails, edit the OPTIONS Method Response:

aws-cors3.png

To add the following headers:

aws-cors4.png

Then repeat Enable CORS from the Actions step.

Finally, deploy the changes:

aws-cors5.png

 

Next steps

Learn about the in-house edition of EDI API.

Learn about how to use InHouse EDI API as Azure Function

 

 

Share this:

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.