S3 Trigger to convert FHIR to CDA format
- Java 17
- AWS SDK - STS or Eclipse
- AWS Account
- Maven 3.3.x
- GIT
Clone the repository using the below command in command prompt
git clone https://github.com/drajer-health/ecr-cda-to-fhir-lambda.git
Import Project as Maven Project Build:
Navigate to ecr-cda-to-fhir-lambda
directory ..../
and run Maven build to build lambda jar file.
$ mvn clean
$ mvn clean install
This will generate a war file under target/ecr-cda-to-fhir-lambda-1.0.0.jar.
Login to your AWS Account
-
Click on Services then select Lambda
-
Click on Create Function
-
Select "Author from Scratch" option
-
Enter:
Function Name: ecrCDA-to-FHIR-lambda
Runtime: Java 17
Permissions: Create a new role with basic Lambda permissions or select your organization specific security
- Click on "Create Function"
At this point Lambda function would be created, navigate to the newly created function and configure the lambda function and environment variable.
-
Go to the newly created Role.
-
Under
Permissions
tab click onCreate inline Policy
-
Click on
{ } JSON
tab and ad the following security policy.Replace the
SQS-NAME
with your SQS name.Replace the
S3-BUCKET-NAME
with your S3 bucket name.Replace the
S3-LIC_BUCKET-NAME
with your S3 bucket name for saxon license.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": "sqs:ReceiveMessage",
"Resource": "arn:aws:sqs:SQS-NAME"
},
{
"Sid": "Statement2",
"Effect": "Allow",
"Action": "sqs:DeleteMessage",
"Resource": "arn:aws:sqs:SQS-NAME"
},
{
"Sid": "Statement3",
"Effect": "Allow",
"Action": "sqs:GetQueueAttributes",
"Resource": "arn:aws:sqs:SQS-NAME"
},
{
"Sid": "ListObjectsInBucket",
"Effect": "Allow",
"Action": [
"s3:GetObjectVersion",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::S3-LIC_BUCKET-NAME/*"
},
{
"Sid": "ListObjectsInBucketS3",
"Effect": "Allow",
"Action": [
"s3:GetObjectVersion",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::S3-BUCKET-NAME/*"
}
]
}
-
Click on button
Next
-
Enter policy name
ecrCdaToFhirLamdaPolcy
-
Click on
Create policy
-
Come back to your AWS Lambda Function and navigate to
Configuration
tab. -
Go to the
General Configuration
and click onEdit
button. Increase the Timeout to minimum 10 minute. -
Under the "Code" tab select "Upload from"
-
Select .zip or .jar file option.
-
Click upload and navigate to your local workspace target folder and select ecr-cda-to-fhir-lambda-1.0.1.jar and click "Save".
-
Click on "Edit" on "Runtime Settings".
-
Enter below value for Handler
com.drajer.ecr.cda2fhir.converter.CDA2FHIRConverterLambdaFunctionHandler::handleRequest
- Click "Save"
To process the file from the S3 bucket, lambda function needs to be configured to process from the specified folder. Add the Environment Variable to the lambda function specifying the S3 bucket folder name.
-
Click on "Configuration" tab and then "Environment Variables"
-
Click on "Edit" to add new environment variable
-
Click on "Add new environment variable"
-
Enter
Environment Variable | Value |
---|---|
BUCKET_NAME | <- S3-FolderName -> |
LICENSE_BUCKET_NAME | <- S3-FolderName -> |
Choose the SQS queue and click Create Queue
-
Select
Standard
and Enter the Name for the Queue aseg: fhir-ecr1-cda-fhir-sqs-queue
-
Enter 10 minutes as Visibility timeout
-
Server-Side encryption as
disabled
-
Access Policy
Advanced
-
Make neccessary changes to below and copy as in-line policy
{
"Version": "2012-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__owner_statement",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "SQS:SendMessage",
"Resource": "arn:aws:sqs:us-east-1:<<AWS_ACCOUNT_INFO>>:<<QUEUE_NAME (from the SQS Queue Step 1)>>",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<<AWS ACCOUNT INFO>>"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::<<S3 BUCKET NAME>>"
}
}
}
]
}
- Click Save
Lambda function needs to be triggered, for this we need to add and configure the trigger. Follow the following steps to add the trigger to your lambda function.
-
Go to you Lambda function
-
Click on
Add trigger
-
From the
Trigger configuration
drop down selectSQS
option -
From the
SQS queque
drop down select your SQS that this lambda function will listen. -
Click Add.
-
Go to S3 bucket and to Properties Tab
-
Scroll down to
Event Notification
and ClickCreate event Notification
-
Enter Name
eg: cda-fhir-event
-
Enter Suffix as
RR_CDA.xml
-
Event Types as
All object create events
-
Destination as
SQS queue
-
Specify SQS queue Enter SQS queque
arn:aws:<<SQS Name (from the SQS Queue Step 1) >>
-
Click
Save Changes
Here are the steps to store the Saxon license in an S3 bucket and configure your AWS Lambda function to use the bucket name as an environment variable:
-
Create an S3 Bucket (if you don't already have one): Go to the AWS Management Console. Navigate to S3. Click on "Create bucket." Choose a unique name for your bucket and select your preferred region. Click "Create bucket."
-
Upload the Saxon License File: In the S3 console, click on your bucket name to open it and create & open license folder if it doesn’t exis Click the "Upload" button. Select the Saxon license file (e.g., saxon-license.lic) from your local file system. Optionally, set the permissions for the file based on your access requirements. Click "Upload."
-
Set Up Environment Variable in Lambda Go to the AWS Management Console. Navigate to the Lambda service. Find and select the Lambda function that you want to configure. Scroll down to the "Environment variables" section. Click on "Edit." Add a new key-value pair: Key: BUCKET_NAME Value: (replace this with the name of your S3 bucket)
-
Test Your Lambda Function In the AWS Lambda console, you can create a test event based on the input your Lambda function expects. Click on "Test" to execute the function and check the logs to verify that it retrieves the license file from S3.
-
Check CloudWatch Logs If there are any issues, check the CloudWatch logs for your Lambda function to debug the problem.
By following these steps, you'll be able to store the Saxon license in an S3 bucket and configure your Lambda function to use the bucket name as an environment variable. If you have any further questions or need assistance with anything else, feel free to ask!