We have an AWS Lambda function in place that dynamically builds test environments for our engineers to test their code through GitHub pull requests.
This Lambda function is called using GitHub webhooks, whereby Github POSTs across all the information needed to configure the test environment for that specific product.
At the moment, the AWS Lambda function is hard coded to parse the POST data and build the test environment. However, as the range of products being tested increases and the range of test environments become more diverse, we are wanting to move away from the hard coded approach; for manageability sake too.
What I want to be able to do, is load a configuration file, preferably in JSON and apply some of the data in the GitHub POST data to the configuration file, essentially injecting the data into the JSON config.
I don't know how to approach this. I've seen a question being asked on here wanting to do something similar, but in Java: Inject dynamically generated data into JSON
Originally our Lambda function was written in Node.js, but we've started to move across to Go - mainly because it was an interesting new challenge. If there is a solution to this in Node.js I'll take that, but if there is a solution available in Go, that would be preferable.
Edit:
The config file and the GitHub POST data have two different structures.
GitHub POST data (heavily stripped down):
{
"action": "opened",
"number": 89,
"pull_request": {
"url": "https://api.github.com/repos/Owner/ExampleRepository/pulls/89",
"head": {
"repo": {
"id": 123454678,
"name": "ExampleRepository"
}
}
}
}
Example Config File (also stripped down):
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": [GitHub Post data].pull_request.url,
"Resources": {
"ElasticBeanstalk": {
"Type": "AWS::ElasticBeanstalk::Environment",
"Properties": {
"ApplicationName": [GitHub Post data].pull_request.head.repo + [GitHub Post data].number,
"Description": [GitHub Post data].pull_request.url
}
}
}
}
Both the config file and the GitHub POST data is much more complex than this. Also, the config file will reference various parts of the POST data multiple times and sometimes would require the concatenation of multiple values.