{"id":23421298,"url":"https://github.com/nhsdigital/terraform-aws-mesh-client","last_synced_at":"2026-07-25T15:30:52.984Z","repository":{"id":196597517,"uuid":"575391360","full_name":"NHSDigital/terraform-aws-mesh-client","owner":"NHSDigital","description":"Reference implementation of a MESH Client in an AWS environment only using serverless technologies.","archived":false,"fork":false,"pushed_at":"2026-07-06T07:54:15.000Z","size":1679,"stargazers_count":5,"open_issues_count":11,"forks_count":5,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2026-07-06T09:16:14.765Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NHSDigital.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGE-LOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-07T12:09:04.000Z","updated_at":"2026-07-06T07:51:33.000Z","dependencies_parsed_at":"2024-04-30T11:15:54.374Z","dependency_job_id":"1c970222-cbf5-42f5-b4e6-46fca783eb7d","html_url":"https://github.com/NHSDigital/terraform-aws-mesh-client","commit_stats":null,"previous_names":["nhsdigital/terraform-aws-mesh-client"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/NHSDigital/terraform-aws-mesh-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fterraform-aws-mesh-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fterraform-aws-mesh-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fterraform-aws-mesh-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fterraform-aws-mesh-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NHSDigital","download_url":"https://codeload.github.com/NHSDigital/terraform-aws-mesh-client/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NHSDigital%2Fterraform-aws-mesh-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35884178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-25T02:00:06.922Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T02:14:43.645Z","updated_at":"2026-07-25T15:30:52.963Z","avatar_url":"https://github.com/NHSDigital.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# terraform-aws-mesh-client\n\nCommon code for MESH AWS serverless client, built and tested by NHS England\n\nRelease Notes\n------------\nsee [CHANGE-LOG](CHANGE-LOG.md) for news on major changes\n\n\n## Usage\n\n# MESH Lambdas\n\nA terraform module to provide AWS infrastructure capable of sending and receiving MESH messages\n\n## Configuration\n\nExample configuration required to use this module:\n\nfind the release you want from https://github.com/NHSDigital/terraform-aws-mesh-client/releases and substitute in the module version below ... e.g. ref=v1.0.1\n\n```terraform\nmodule \"mesh\" {\n  source = \"git::https://github.com/nhsdigital/terraform-aws-mesh-client.git//module?ref=\u003cversion\u003e\"\n\n  name_prefix = \"${var.env}-example-project\"\n  mesh_env    = \"production\"  # local/production/integration\n  vpc_id      = aws_vpc.my_vpc.id\n  subnet_ids  = aws_subnet.private.*.id\n  \n  mailbox_ids = [\"X26ABC123\", \"X26ABC456\"]  # your mesh mailbox id(s)\n  verify_ssl  = true  # set false for local\n\n  get_message_max_concurrency = 10 \n\n  compress_threshold = 1 * 1024 * 1024\n\n  # vpc endpoints are required if deploying the module into a VPC\n  aws_s3_endpoint_prefix_list_id = aws_vpc_endpoint.s3.prefix_list_id\n  aws_ssm_endpoint_sg_id         = tolist(aws_vpc_endpoint.ssm.security_group_ids)[0]\n  aws_sfn_endpoint_sg_id         = tolist(aws_vpc_endpoint.sfn.security_group_ids)[0]\n  aws_logs_endpoints_sg_id       = tolist(aws_vpc_endpoint.logs.security_group_ids)[0]\n  aws_kms_endpoints_sg_id        = tolist(aws_vpc_endpoint.kms.security_group_ids)[0]\n  aws_lambda_endpoints_sg_id     = tolist(aws_vpc_endpoint.lambda.security_group_ids)[0]\n  aws_secrets_endpoints_sg_id    = tolist(aws_vpc_endpoint.secrets.security_group_ids)[0]\n  \n  # region = \"eu-west-2\"\n  # verify_checks_common_name = false \n  # cloudtrail_enabled = false  # (set false for localstack) \n  # use_secrets_manager = true  # use secrets manager for storage of keys or passowrds rather than SSM\n  # use_sender_filename = true  # allow the sender to define the filename to store in your s3 bucket ( not recommeded )\n  # use_legacy_inbound_location = true # support for v1 outbound mapping of send parameters via SSM\n  # chunk_size = number # size of chunks to send to MESH ( advanced tuning ), leave as default if you don't need to tune\n  # crumb_size = number # size of buffer reading from s3 or from MESH (very advanced tuning), leave as default if you don't need to tune  \n  # never_compress = true  # disable all outbound compression, regardless of `mex-content-compress` instruction or `compress_threshold`\n  \n}\n```\n\nRelease versions will be pushed to [releases](https://github.com/NHSDigital/terraform-aws-mesh-client/releases) as git tags, with the format `v\u003cmajor\u003e.\u003cminor\u003e.\u003cpatch\u003e` such as `v1.0.1`\n\n### Advanced Configuration\nThe module has many configuration options, rather than duplicate descriptions here, please see [variables.tf](module/variables.tf)\n\n# Send File\n\nSend a file by doing a 'put_object', Cloudtrail and cloudwatch event triggers will detect any file put into the bucket in the `outbound/*` location and send to MESH.\nDetails:\n* MESH `mex-*` headers will be honoured and passed the [MESH Client](https://github.com/NHSDigital/mesh-client), where appropriate\n* metadata will be inspected first for a `mex-from` (sender mailbox id), metadata parameter, if present this and other metadata will be used, if `mex-from` is not found, we will fall-back to using the outbound mappings as the source for `mex-from`, `mex-to` and `mex-workflowid`\n* S3 object metadata supports a limited character set, and size; Metadata values should be encoded with the equivalent of [urllib.parse.quote_plus](https://docs.python.org/3/library/urllib.parse.html), e.g.  `s3_client.put_object(..., Metadata={\"mex-subject\": quote_plus(subject),..)` ... before sending to MESH the inverse `unquote_plus` will be applied.\n* `mex-` metadata keys are case-insensitive, keys will be converted to lower case before comparison or sending to MESH.\n* using s3 object metadata allows the configuration of many more mesh parameters, including but not limited to:\n    * `mex-from` sender MESH mailbox id (your mailbox)\n    * `mex-to` recipient MESH mailbox id (recipient mailbox)\n    * `mex-workflowid` MESH workflow id\n    * `mex-subject` (optional) 'free text' subject area,\n    * `mex-localid` (optional) sender supplied unique identifier\n    * `mex-filename` (optional) passthrough file name passed to recipient, if not set MESH will set a default file name of `{message_id}.dat`\n    * `mex-content-compress` (optional) explicit instruction to compress the content before sending to MESH, this will override exclusions based on `mex-content-compressed` and `content-encoding`\n    * `mex-content-compressed` (optional) passthrough indication this file is already compressed, if set the send application will never auto-compress, regardless of the file size and `compress_threshold` configured\n    * `mex-content-encrypted` (optional) passthrough indicator to signify that the file has been encrypted (MESH does nothing with this)\n\n## Example Send File\n```python\nfrom urllib.parse import quote_plus\nfrom uuid import uuid4\n\nimport boto3\n\nsender = \"X26MYMAILBOXID\"\nrecipient = \"X26RECIPIENT\"\nmy_id = uuid4().hex\nbucket = \"...\"  # mesh outbound bucket\nkey = f\"outbound/{sender}/{my_id}.json\"\nmetadata = {\n  \"mex-From\": sender,\n  \"mex-To\": recipient,\n  \"mex-WorkflowId\": \"PATHOLOGY_RESULT\",\n  \"mex-Subject\": \"my super subject $£% etc\",\n  \"mex-LocalId\": my_id,\n}\nmetadata = {k: quote_plus(v) for k, v in metadata.items()}  # don't forget to escape metadata values\n\nboto3.client(\"s3\").put_object(\n  Bucket=bucket, Key=key, ContentType=\"application/json\", Metadata=metadata\n)\n\n```\n\n\n# Receive File\n\nBy default, received files will be stored in the MESH s3 bucket in the pattern  `inbound/{recipient_mailbox_id}/{message_id}.dat` (or `inbound/{recipient_mailbox_id}/{message_id}.ctl` for reports). \n- It is possible to override this behaviour to support legacy usage and some customisation, though it's recommended to go with the defaults.\n- MESH headers will be honoured and stored on the [S3 object metadata](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html):\n- It's recommended to configure a Cloudwatch event trigger to monitor for new mesh messages and perform the appropriate action:\n\n## Example terraform configuration\n\n```terraform\nresource \"aws_cloudwatch_event_rule\" \"new_mesh_message\" {\n  name        = \"${var.environment}-new-mesh-message\"\n  description = \"new mesh message received\"\n  event_pattern = jsonencode({\n    source = [\n      \"aws.s3\"\n    ]\n    detail = {\n      eventSource = [\n        \"s3.amazonaws.com\"\n      ]\n      eventName = [\n        \"PutObject\",\n        \"CompleteMultipartUpload\"\n      ]\n      requestParameters = {\n        bucketName = [\n          module.mesh.mesh_s3_bucket_name\n        ]\n        key = [\n          {\n            prefix = \"inbound/\"\n          }\n        ]\n      }\n    }\n  })\n}\n\nresource \"aws_cloudwatch_event_target\" \"new_mesh_message\" {\n  rule      = aws_cloudwatch_event_rule.new_mesh_message.name\n  target_id = \"NewMessage\"\n  arn       = aws_lambda_function.new_mesh_message.arn\n  role_arn  = \"...\"\n}\n\nresource \"aws_lambda_function\" \"new_mesh_message\" {\n  function_name = \"${var.environment}-new-mesh-message\"\n  handler       = \"new_mesh_message.handler\"\n  role          = \"...\"\n}\n```\n## Example new mesh message lambda function code: \n```python\nimport json\nimport logging\nfrom typing import Any\nfrom urllib.parse import unquote_plus\n\nimport boto3\n\ns3 = boto3.resource(\"s3\")\n\ndef on_new_message(_sender: str, _workflow_id: str, _payload: dict[str, Any]):\n    raise NotImplementedError\n\n\ndef handler(event: dict[str, Any], _context=None):\n    s3_bucket = event[\"detail\"][\"requestParameters\"][\"bucketName\"]\n    s3_key = event[\"detail\"][\"requestParameters\"][\"key\"]\n\n    new_message = s3.Object(bucket_name=s3_bucket, key=s3_key)\n    \n    mesh_metadata = {\n        k.lower(): unquote_plus(v)\n        for k, v in new_message.metadata\n        if k.lower().startswith(\"mex-\")\n    }\n\n    message_id = mesh_metadata[\"mex-messageid\"]\n    sender = mesh_metadata[\"mex-from\"]\n    recipient = mesh_metadata[\"mex-from\"]\n    workflow_id = mesh_metadata.get(\"mex-workflowid\")\n    message_type = mesh_metadata.get(\"mex-messagetype\")\n    \n    logging.info(f\"new mesh message: message_id={message_id} sender={sender} recipient={recipient} workflow_id={workflow_id} message_type={message_type}\")\n    \n    if message_type == \"REPORT\":\n        # todo: store report info, do I need to notify / report on failures?\n        return \n    \n    response = new_message.get()\n    payload = json.loads(response[\"Body\"].read())\n    on_new_message(sender, workflow_id, payload)\n\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhsdigital%2Fterraform-aws-mesh-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhsdigital%2Fterraform-aws-mesh-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhsdigital%2Fterraform-aws-mesh-client/lists"}