This terraform module represents Lambda instance responsible for updating configs.json configuration, used by Web Docker.
WebDocker is a tool used to dynamically inject assets (JS and CSS) to website and render them afterward. It is mostly used for delivery of microfrontends to the overall project, providing multiple ways to trigger the assets injection.
More information about the WebDocker injection mechanism can be found in WebDocker repository.
In order for WebDocker to work, it requires a JSON file with configuration for the asset injection. Each microfrontend can set it's own trigger events or pages where assets will be injected, and the JSON file also contains references to the assets itself ( absolute paths to JS and CSS assets ).
This JSON file is hosted on AWS S3 bucket publicly accessible and is loaded on each page load by the WebDocker itself.
This configuration file is generated by the WebDocker Config Update Lambda. Since each microfrontend can be developed separately, Microfrontends deploy their own partial configurations ( configuration just for that particular microfrontend ) to a S3 bucket managed by this repository.
Once partial configuration is successfully deployed as part of the microfrontend pipeline, a S3 bucket notification event is sent, which triggers the lambda invocation.
Lambda triggers a javascript function found in index.js
, which lists all the partial configurations, concatenates them together into general JSON configuration and deploys it to the public bucket where WebDocker can access it.
The public S3 bucket is used as a source for the WebDocker to load the configuration file, and needs to be accessible to the public. This part of infrastructure should already be set up and managed elsewhere.
Most of the variables used have a default value, list of the variables that are required is below.
Please provide the following variables to terraform if deploying to your infrastructure using .tfvars
files of TF_VARS_
environment variables:
environment
aws_account_id
Please provide the following variable to terraform via TF_VAR_
environment variable:
TF_VAR_STATE_BUCKET
for bucket for state file
arn
- lambda function ARN
brew install terraform
terraform init -upgrade -backend-config=bucket=$TF_VAR_STATE_BUCKET
terraform plan -var-file environment.tfvars
terraform apply
terraform destroy
aws lambda update-function-code --function-name=webdocker-config-update --s3-bucket=${LAMBDA_BUCKET_NAME} --s3-key=webdocker-config-update/latest.zip --publish
- Always use snake_case for output variables