The repository is structured as follows:
./
| .gitignore
| Dockerfile
| README.md
|
+---.github
| \---workflows
| deploy-project.yaml
|
+---iac
| | backend.tf
| | locals.tf
| | main.tf
| | output.tf
| | provider.tf
| | variables.tf
| | versions.tf
| |
| \---modules
| \---generic
| locals.tf
| main.tf
| output.tf
| variables_aws_api_gateway.tf
| variables_aws_cognito.tf
| variables_aws_ecr_repository.tf
| variables_aws_lambda_event_source_mapping.tf
| variables_lambda_function.tf
| variables_lambda_permission.tf
| versions.tf
|
\---src
lambda_function.py
- This generic module executes the download of remote modules from the repository terraform-modules-remotes.
- The generic module is located in the directory ./iac/modules/generic.
- This project utilization modules:
The lambda_function.py is a key component of this repository, which contains Terraform modules for AWS resources. This function enables the registration of new users in an Amazon Cognito User Pool by collecting user information, checking if the email is already in use, and registering the user if everything is correct.
Key Features:
RZeceives User Data: The function accepts an event containing the username, password, and email.
Checks Email: Verifies if the provided email is already confirmed and in use.
Registers User: If the email is not in use, it registers the user in Cognito and returns a success message.
How It Works:
Necessary Imports: Utilizes libraries such as boto3 for interacting with Cognito and hmac for generating an authentication hash.
Calculates Secret Hash: Generates a hash using HMAC and SHA-256, which is essential for authenticating the request. Event Handling: Processes the received event to extract user data.
User Registration in Cognito: Attempts to register the user and returns a success or error response.
Example Usage: The event should follow this structure:
curl --location 'https://techchallenge.com.br/api/v1/register' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data-raw '{
"username": "111.111.111.11",
"password": "Teste@2024!!,",
"email": "teste@gmail.com"
}'
Common Errors:
Email Already in Use: Returns an error if the email is already registered.
Registration Issues: Any error during registration generates an appropriate error message.