This project consists of a processing function for creating a list of released clients in a new database, having as source the customers already registered in the legacy database.
The flow starts with a scheduled execution through an AWS event.
When starting, eligible customers are founded.
When finding these customers:
- Each customer found will be verified if it is a person or legal entity;
- Customers validated in the previous step will be added into the new database;
- Customers added in the previous item will have their processing time scheduled so they are not eligible for new processing.
Requires an event to start.
This function was built using the following technologies:
- aws-lambda-go - v1.32.1;
- aws-sdk-go - v1.44.51;
- aws-xray-sdk-go - v1.7.0;
- cleanenv v1.3.0;
- go_ibm_db - v0.4.1;
- go-sqlmock - v1.5.0;
- mysql - v1.6.0;
- testify v1.7.5;
- zerolog v1.27.0.
All instructions can be found here: go_ibm_db
But I'll put the step by step the way I understand to make it easier:
Download the dependency to your library:
go get -d github.com/ibmdb/go_ibm_db
At the end you will see that it has been installed in:
{GO_PATH}/src/github.com/ibmdb/go_ibm_db
Install ODBCCLI, this is a simple process, the library itself created a file for you to do this automatically.
Look for:
${GO_PATH}/src/github.com/ibmdb/go_ibm_db/installler
and run:
go run setup.go
After CLIDRIVER is downloaded, you need to set the following environment variables:
Variable | Value |
---|---|
DB2HOME | ${GO_PATH}/src/github.com/ibmdb/go_ibm_db/installer/clidriver |
CGO_CFLAGS | I$DB2HOME/include |
CGO_LDFLAGS | L$DB2HOME/lib |
❗ LINUX
Variable | Value |
---|---|
LD_LIBRARY_PATH | ${GO_PATH}/src/github.com/ibmdb/go_ibm_db/installer/clidriver/lib |
❗ MAC
IF YOU ARE USING A recent OSX, this variable must be set at runtime
Variable | Value |
---|---|
DYLD_LIBRARY_PATH | ${GO_PATH}/src/github.com/ibmdb/go_ibm_db/installer/clidriver/lib |
Add the license file in the CLIDRIVER folder.
Look for:
${GO_PATH}/src/github.com/ibmdb/go_ibm_db/installer/clidriver/license
and add the DB2 license file (usually the name is: db2consv_ee.lic)
Variable | Variable description | Default value |
---|---|---|
LOG_LEVEL | Log level. | info |
MYSQL_OPEN_CONN_MAX | Maximum number of connections that can be opened. | 100 |
MYSQL_IDLE_CONN_MAX | Maximum number of connections that can be stopped. | 2 |
MYSQL_LIFE_CONN_MAX | Maximum connection time in seconds. | 10 |
DB2_OPEN_CONN_MAX | Maximum number of connections that can be opened. | 100 |
DB2_IDLE_CONN_MAX | Maximum number of connections that can be stopped. | 2 |
DB2_LIFE_CONN_MAX | Maximum connection time in seconds. | 10 |
AWS_REGION_NAME | Region where the secrets manager is located. | DEFINE_REGION_NAME |
SECRETS_MANAGER | Name of the secret manager used in the application | SECRETS_MANAGER |
DATASOURCE_LIMIT | Number of records that will be loaded per event. | 100 |
To upload a function you need to create and build it like linux operating. So use the following command in the project folder:
$ GOOS=linux GOARCH=amd64 go build -o MIGRATION_CUSTOMERS ./
or you can use Makefile.
$ make build
❗ Attention️
- After the build, you need to create the .zip of the generated file and then upload this .zip file;
- The Handler is the name of the generated .zip file.
- This project is a part of a proof of concept used in the company, so parts of them were omitted as well as domain and data model information.
- As the execution was sporadic, it was chosen to use it as a lambda, so there was no need to allocate a container and the execution time was acceptable for the solution.
- Another reason chosen was the possibility for the operator to request the execution whenever necessary.