AWS components¶
All components within a AWS-based MACH configuration are automatically considered to have a 'aws' integration by default. Only if 'aws' is explicitely omitted from the integrations
definition, it won't require any AWS-specific variables.
To be able to create the resources needed, a couple of extra Terraform variables are set by MACH.
In addition to this, the component itself is responsible for packaging and deploying the correct assets in case of a Lambda function.
Terraform variables¶
In addition to the base variables AWS components don't require additional variables, unless an endpoint
is expected (and set in the configuration).
With endpoints
¶
In order to support the endpoints
attribute on the component, the component needs to define what endpoints it expects.
For example, if the component requires two endpoints (main
and webhooks
) to be set, the following variables needs to be defined:
variable "endpoint_main" {
type = object({
url = string
api_gateway_id = string
api_gateway_execution_arn = string
})
}
variable "endpoint_webhooks" {
type = object({
url = string
api_gateway_id = string
api_gateway_execution_arn = string
})
}
Packaging and deploying¶
AWS Lambda functions need to be uploaded to a S3 bucket. From there AWS Lambda will run the functions for you once instructed by the Terraform deployment.
Read more about AWS component deployments.
Configure runtime¶
When defining your AWS Lambda function resource, you can reference back to the asset that is deployed:
resource "aws_lambda_function" "example" {
s3_bucket = "your-lambda-repo"
s3_key = "yourcomponent-${var.component_version}.zip"
...
}
HTTP routing¶
MACH will provide the correct HTTP routing for you.
To do so, the following has to be configured:
Default endpoint
If you assign default
to one of your components endpoints, no additional Route53 settings are needed.
MACH will create an API Gateway for you without any custom domain.
More information in the deployment section.
Lambda function¶
We recommend using the AWS Lambda Terraform module for managing a Lambda function.
module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"
function_name = "${var.site}-${var.short_name}"
handler = "src/index.handler"
runtime = "nodejs12.x"
memory_size = 512
timeout = 10
environment_variables = local.environment_variables
create_package = false
s3_existing_package = {
bucket = local.lambda_s3_repository
key = local.lambda_s3_key
}
}