Custom API Import - Lambda
Overview
Relyance provides a robust method of connecting to your internal systems securely. This method not only ensures a tight-knit security layer but also ensures your team can have peace of mind.
Benefits of using a custom AWS Lambda for Integration with Relyance:
Data Confidentiality: You can keep your database username and password confidential. By integrating with Relyance this way, you won't have to share these critical credentials, ensuring an added layer of security.
Temporary Access: Relyance will assume a role you provide. Following this, AWS's Security Token Service (STS) springs into action, offering temporary security credentials. These credentials come with a session token that's time-bound - they can be configured to last as short as 15 minutes. So, even in an unforeseen situation, there's a minimal window of opportunity for any malicious intent.
No Direct Access: With this integration, you'll be keeping Relyance and other third-party entities at arm's length from your internal service. Since you have full control and can trust the Lambda function acting as a mediator, threats of unauthorized access or unintended permission escalations are virtually non-existent.
Prerequisites:
In order to create a Custom API Import- Lambda with Relyance AI you will need:
- A Relyance Admin account.
- Access to your AWS console.
- The ability to create roles.
- The ability to create Lambdas.
- API access to the service in question.
- An understanding of how to access the API via code.
A few important notes:
- This is a basic example and will need adjustments based on the specifics of the API endpoint you are trying to access.
- Ensure your Lambda has the necessary permissions to access the internet if your service is outside the VPC.
- You may need to install package dependencies when creating the lambda deployment package
Steps to create the Lambda Function in Amazon AWS
When you connect your Amazon Lambda function to Relyance you will need your Account ID, Role Name, External ID, Region, Lambda Function Name, Secret Name, and Region for secret. Follow the below steps to create them.
- Log in to your AWS management console.
- Copy your Account ID from the top-right profile dropdown menu. IAM Role for AWS Lambda This allows AWS to initiate the Lambda function.
- Navigate to the IAM console and create a new role.
- Choose Lambda as the AWS service that will use this role.
- Grant permissions for:
- AWSLambdaVPCAccessExecutionRole
- AWSLambdaRole
- Provide a meaningful Role name (e.g. RelyanceLambdaServiceName)
- Create the role.
- Note the Role name to be used in Relyance. Add Lambda Build out your Lambda function using your custom code.
- Navigate to the Lambda section in AWS and click on Create function.
- Choose Author from Scratch.
- Provide a meaningful name (e.g. RelyanceLambdaCustomAPI)
- In the Runtime, choose Python 3.9.
- For Architecture choose x86_64.
- Open up Change default execution role and select the Use an existing role radio button.
- Find the Role previously created.
- Under Advanced settings, choose Enable VPC. Choose the same VPC as the proxy.
- Use the same subnets as the proxy.
- Use the same security groups as the proxy.
- Create the function.
- Note the Function Name to be used in Relyance.
- Go to the Configuration tab and click Edit.
- Update the function Timeout to 10 minutes under Basic settings. Code Include the code that will pull in the data from your internal systems and respond to the Relyance query.
- In the Code section of your Lambda function provide the code needed to access your internal services/Saas tool. Access, authorization, and credentials to other tools fall beyond the scope of this article. Example code:
import json
def lambda_handler(event, context):
result = [{
"id": 1,
"name" : "John",
"email": "john@jo.hn"
},
{
"id": 2,
"name" : "Jane",
"email": "jane@jo.hn"
}
]
return {
'statusCode': 200,
'data': result
}The important part is the Lambda function will return a response JSON payload with the data needing to be analyzed. Ensure you Deploy your code changes. Update the new Role for Relyance to execute the Lambda This section should be done after you create your Lambda function and associate it to your role. 24. Create an External ID - this can be anything. (e.g. '9599ec49-abb3-47bb-a5b6-86c79fc10d32') The external ID is a secret that you will use and enter in the Relyance platform for additional security. While it could be anything, we recommend using a secret generator such as https://www.uuidgenerator.net/version4 to generate. 25. Navigate to IAM> Roles section and open the previously created role. 26. Open the new role (eg. RelyanceLambdaServiceName) and click on the Trust Relationships tab and update the trust policy from this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}to this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com",
"AWS": "arn:aws:iam::580082088342:user/tenant-prod-access"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "<< external ID >>"
}
}
}
]
}Ensure you replace '<< external ID >>' with the external ID you created previously. Other settings 27. Select which Region your AWS instance should use (e.g. us-east-1).
In the Relyance AI application:
- Login to your Relyance account.
- Navigate to the Settings Menu in the bottom left-hand side.
- Select Integrations.
- Click on the Vendors filter.
- Find the Custom Data Import integration card and click it to open its connections.
- Under Authentication Method, choose AWS Lambda.
- Paste the following need into their respective fields. Name of Target Vendor: Choose the vendor this integration relates to. Name of the Internal Service (optional): Is this integration relates to an internal service. JSON Config: -account-id: This is your AWS account ID.
- role-name: The role you initially created.
- external-id: This is the generated ID you created for the Trust relationship.
- region: The region the role and lambda are created in.
- lambdas:
{
"accounts": [
{
"account-id": "123456789",
"role-name": "RelyanceLambdaServiceName",
"external-id": "9599ec49-abb3-47bb-a5b6-86c79fc10d32",
"region": "us-east-1",
"lambdas": [
{
"function_name": "RelyanceLambdaCustomAPI",
"results_field": "data",
"result_record_type": "person",
"unique_id_field": "id"
}
]
}
]
}Data Inspection:
- Enable Data Inspection: Enable data inspection of the data values.
- Min Likelihood: Set the likelihood of returned results. The Min Likelihood sets the analysis sensitivity of the data inspection. Lower likelihoods (unlikely) provide more coverage but may generate false positives, while higher sensitivity (very likely) provides more accuracy but may have less coverage.
- TTL for QC Samples: The number of days to retain data samples for the purposes of QC.
- Click Authenticate.
- At this point, you should see the following result on the integrations page:


- Congratulations, you are now connected to Custom API Import.