Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Serverless Pattern - s3-b2bi-s3- EDI to JSON tranformation #2091

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions s3-b2bi-s3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SAM default build folder
.aws-sam/

# macOS
*.DS_Store

#VS Code
.vscode/
102 changes: 102 additions & 0 deletions s3-b2bi-s3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Transform EDI to JSON using AWS B2B Data Interchange

This sample project demonstrates how AWS B2B Data Interchange can transform EDI Files into JSON as per the transformation logic.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/s3-b2bi-s3

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

## Requirements

- [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
- [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed


## Deployment Instructions

1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
```bash
git clone https://github.com/aws-samples/serverless-patterns
```
2. Change directory to the pattern directory:
```bash
cd s3-b2bi-s3
```
3. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
```bash
sam deploy -g -t template-part1.yaml
```
4. During the prompts:

- Enter a stack name. I am assuming the stack name to be `b2bi-stack1`.
- Enter the desired AWS Region. Please refer to the documentation for the list of supported regions.
- Enter `BusinessName`, `Email` and `Phone`.

5. Note the outputs from the SAM deployment process. These contain the resource names and/or Ids which are used for the next step as well as testing.

6. Log into [AWS B2B Data Interchange](https://us-east-1.console.aws.amazon.com/b2bi/home). Click on the Transformers tab on the left hand navigation menu. Click on the `MyTransformer`. Click on the `Set Status` button and select `Active`. Please ensure that the `MyTransformer` status is set to `Active`.

7. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
```bash
sam deploy -g -t template-part2.yaml
```
8. During the prompts:

- Enter a stack name. I am assuming the stack name to be `b2bi-stack2`.
- Enter the desired AWS Region. Please refer to the documentation for the list of supported regions.
- Enter `BusinessName`, `Email`, `Phone`, `EDI214InputBucketName`, `EDI214OutputBucketName`, `MyProfileId` and `MyTransformerId`. Please note the last four parameter values should be given as per the output from the `b2bi-stack1` output.



## How it works


Please refer to the architecture diagram below:

![End to End Architecture](images/architecture.png)

* An X12 EDI file is uploaded into the input Amazon S3 bucket.
* File upload action triggers AWS B2B Data Interchange Transformers to transform the X12 EDI file into JSON format.
* The transformed JSON file is uploaded into the output Amazon S3 bucket.

## Testing


1. Log into the [Amazon S3 console](https://s3.console.aws.amazon.com/s3/buckets) open `edi-214-input-{your-account}-{your-region}` bucket. Navigate to folder `input/tp-xxxxxxxxxxxx`. Upload the `sample-edi-214.edi` file into this folder.

2. Now, after a few seconds, open `edi-214-output-{your-account}-{your-region}` bucket. Navigate to folder `input/tp-xxxxxxxxxxxx`. Download the transformed JSON output file. The content of the downloaded JSON file should look like:
```json
{
"ReferenceID": "MSKU0123456",
"ShipmentID": "90800706",
"BillOfLandingNumber": "MAEU112233444",
"ShipmentStatusCode": "LY"
}
```


## Cleanup

1. Delete the content in the Amazon S3 bucket using the following command. Please *ensure* that the correct bucket name is provided to avoid accidental data loss:
```bash
aws s3 rm s3://{EDI214InputBucketName} --recursive --region {my-region}
```

2. Delete the content in the Amazon S3 bucket using the following command. Please *ensure* that the correct bucket name is provided to avoid accidental data loss:
```bash
aws s3 rm s3://{EDI214OutputBucketName} --recursive --region {my-region}
```

3. To delete the resources deployed to your AWS account via AWS SAM, run the following command:
```bash
sam delete --stack-name {b2bi-stack2}
sam delete --stack-name {b2bi-stack1}
```

---

Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
63 changes: 63 additions & 0 deletions s3-b2bi-s3/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"title": "Transform EDI to JSON using AWS B2B Data Interchange",
"description": "This sample project demonstrates how AWS B2B Data Interchange can transform EDI Files into JSON as per the transformation logic.",
"language": "YAML",
"level": "200",
"framework": "SAM",
"introBox": {
"headline": "How it works",
"text": [
"An X12 EDI file is uploaded into the input Amazon S3 bucket.",
"File upload action triggers AWS B2B Data Interchange Transformers to transform the X12 EDI file into JSON format.",
"The transformed JSON file is uploaded into the output Amazon S3 bucket."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/s3-b2bi-s3",
"templateURL": "serverless-patterns/s3-b2bi-s3",
"projectFolder": "s3-b2bi-s3",
"templateFile": "template-part1.yaml"
}
},
"resources": {
"bullets": [
{
"text": "AWS B2B Data Interchange User Guide",
"link": "https://docs.aws.amazon.com/b2bi/latest/userguide/what-is-b2bi.html"
},
{
"text": "AWS Blog - Manage EDI at scale with new AWS B2B Data Interchange",
"link": "https://aws.amazon.com/blogs/aws/introducing-aws-b2b-data-interchange-simplified-connections-with-your-trading-partners/"
}
]
},
"deploy": {
"text": [
"See the GitHub repo for detailed deployment instructions.",
"sam deploy -g -t template-part1.yaml",
"sam deploy -g -t template-part2.yaml"
]
},
"testing": {
"text": [
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
"text": [
"Delete the Amazon S3 input bucket content: <code>aws s3 rm s3://{EDI214InputBucketName} --recursive --region {my-region}</code>",
"Delete the Amazon S3 output bucket content: <code>aws s3 rm s3://{EDI214OutputBucketName} --recursive --region {my-region}</code>",
"Delete the stack1: <code>sam delete --stack-name {b2bi-stack2}</code>.",
"Delete the stack1: <code>sam delete --stack-name {b2bi-stack1}</code>."
]
},
"authors": [
{
"name": "Biswanath Mukherjee",
"image": "https://d1rwvjey2iif32.cloudfront.net",
"bio": "I am a Sr. Solutions Architect working at AWS India.",
"linkedin": "biswanathmukherjee"
}
]
}
Binary file added s3-b2bi-s3/images/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions s3-b2bi-s3/s3-b2bi-s3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"title": "Transform EDI to JSON using AWS B2B Data Interchange",
"description": "This sample project demonstrates how AWS B2B Data Interchange can transform EDI Files into JSON as per the transformation logic.",
"language": "YAML",
"level": "200",
"framework": "SAM",
"introBox": {
"headline": "How it works",
"text": [
"An X12 EDI file is uploaded into the input Amazon S3 bucket.",
"File upload action triggers AWS B2B Data Interchange Transformers to transform the X12 EDI file into JSON format.",
"The transformed JSON file is uploaded into the output Amazon S3 bucket."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/s3-b2bi-s3",
"templateURL": "serverless-patterns/s3-b2bi-s3",
"projectFolder": "s3-b2bi-s3",
"templateFile": "template-part1.yaml"
}
},
"resources": {
"bullets": [
{
"text": "AWS B2B Data Interchange User Guide",
"link": "https://docs.aws.amazon.com/b2bi/latest/userguide/what-is-b2bi.html"
},
{
"text": "AWS Blog - Manage EDI at scale with new AWS B2B Data Interchange",
"link": "https://aws.amazon.com/blogs/aws/introducing-aws-b2b-data-interchange-simplified-connections-with-your-trading-partners/"
}
]
},
"deploy": {
"text": [
"See the GitHub repo for detailed deployment instructions.",
"sam deploy -g -t template-part1.yaml",
"sam deploy -g -t template-part2.yaml"
]
},
"testing": {
"text": [
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
"text": [
"Delete the Amazon S3 input bucket content: <code>aws s3 rm s3://{EDI214InputBucketName} --recursive --region {my-region}</code>",
"Delete the Amazon S3 output bucket content: <code>aws s3 rm s3://{EDI214OutputBucketName} --recursive --region {my-region}</code>",
"Delete the stack1: <code>sam delete --stack-name {b2bi-stack2}</code>.",
"Delete the stack1: <code>sam delete --stack-name {b2bi-stack1}</code>."
]
},
"authors": [
{
"name": "Biswanath Mukherjee",
"image": "https://d1rwvjey2iif32.cloudfront.net",
"bio": "I am a Sr. Solutions Architect working at AWS India.",
"linkedin": "biswanathmukherjee"
}
],
"patternArch": {
"icon1": {
"x": 20,
"y": 50,
"service": "s3",
"label": "Input bucket"
},
"icon2": {
"x": 50,
"y": 50,
"service": "internet",
"label": "B2B Data Interchange"
},
"icon3": {
"x": 80,
"y": 50,
"service": "s3",
"label": "Output bucket"
},
"line1": {
"from": "icon1",
"to": "icon2",
"label": ""
},
"line2": {
"from": "icon2",
"to": "icon3",
"label": ""
}
}
}
20 changes: 20 additions & 0 deletions s3-b2bi-s3/sample-edi-214.edi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ISA*00* *00* *ZZ*Superpower *ZZ*Iris *231122*0830*Y*00401*000001011*0*P*>~
GS*QM*Superpower Batteries*Iris Cameras*20231122*0830*1010*X*004010~
ST*214*5598~
B10*MSKU0123456*90800706*RKNE~
L11*MAEU112233444*BM~
L11*NoARN*BX~
L11*1*QN~
N1*SH*Superpower Batteries ABC1~
N3*5591 S 48th St~
N4*Lincoln*NH*68516*USA~
N3*53 Hillside Rd*GATE 4~
N4*Cranston*RI*02920*USA~
LX*1~
AT7*LY*NS***20231122*0202*PT~
MS1*Lincoln*NH*USA~
MS2*MSKU*123456*TL*7~
L11*MSKU1234567*EQ~
SE*16*5598~
GE*1*1010~
IEA*1*000001011~
Loading