{"id":21213977,"url":"https://github.com/cruxstack/cognito-custom-message-sender-go","last_synced_at":"2025-04-13T22:05:08.840Z","repository":{"id":229355966,"uuid":"775677931","full_name":"cruxstack/cognito-custom-message-sender-go","owner":"cruxstack","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-05T22:51:07.000Z","size":22,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-20T21:30:43.238Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cruxstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-21T20:47:49.000Z","updated_at":"2024-11-05T22:51:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"416db0be-b2d5-4c19-a86f-f653f25eb6bb","html_url":"https://github.com/cruxstack/cognito-custom-message-sender-go","commit_stats":null,"previous_names":["cruxstack/cognito-custom-message-sender-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cruxstack%2Fcognito-custom-message-sender-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cruxstack%2Fcognito-custom-message-sender-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cruxstack%2Fcognito-custom-message-sender-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cruxstack%2Fcognito-custom-message-sender-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cruxstack","download_url":"https://codeload.github.com/cruxstack/cognito-custom-message-sender-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234979245,"owners_count":18916755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-11-20T21:25:18.403Z","updated_at":"2025-01-21T16:20:56.351Z","avatar_url":"https://github.com/cruxstack.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cognito Custom Message Sender\n\nThis AWS Lambda-based solution enables dynamic, policy-driven email responses to\nAWS Cognito events, utilizing AWS Simple Email Service (SES) for delivery.\nTailor email content and sending behavior dynamically with Open Policy Agent\n(OPA) policies, providing a flexible and powerful tool for managing user\ncommunications in response to specific triggers within AWS Cognito. Ideal for\napplications requiring customized user engagement or notification strategies.\n\n## Features\n\n- **AWS Lambda Integration**: Handle Cognito Custom Email Sender events, sending\n  emails according to OPA policies.\n- **Policy-based Email Sending**: Use OPA for fine-grained control over email\n  content and sending behavior.\n\n## Lambda Function\n\nTrigger the Lambda function by configuring Cognito to send Custom Email Sender\nevents. Ensure your Lambda function is set as the destination for these events.\n\n### Build\n\n#### Prerequisites\n\n- AWS account with access to SES, Lambda, and KMS.\n- Configured AWS CLI with appropriate permissions.\n- Go 1.22.1+ installed for building the project.\n- Knowledge of Open Policy Agent for defining policies.\n\n#### Steps\n\n1. Clone the repository:\n\n    ```bash\n    git clone https://github.com/cruxstack/cognito-custom-message-sender-go.git\n    cd cognito-custom-message-sender-go\n    ```\n\n2. Build the project for Linux as `bootstrap` binary:\n\n    ```bash\n    GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bootstrap\n    ```\n\n3. Add OPA Policy:\n\n    ```rego\n    package cognito_custom_sender_email_policy\n    result := {\n        \"action\": \"allow\",\n        \"allow\": {\n            \"templateID\": \"REPLACE_WITH_SES_TEMPLATE_NAME\",\n            \"templateData\": {},\n            \"srcAddress\": \"noreply@example.com\",\n            \"dstAddress\": input.userAttributes.email,\n        },\n    }\n    ```\n\n4. Create a ZIP archive:\n\n    ```bash\n    zip deployment.zip main policy.rego\n\n    ```\n\n### Create Lambda Function\n\n#### Steps\n\n- Create a KMS key in the AWS Management Console\n    - Required as AWS uses it to encrypt the verification code.\n- Create a IAM Role with the following permissions:\n    - `AWSLambdaBasicExecutionRole` Managed Policy\n    - `kms:Decrypt` for the KMS key\n    - `ses:GetTemplate` for fetching SES templates\n    - `ses:SendTemplatedEmail` for sending emails\n- Create a Lambda function in the AWS Management Console\n    - Runtime: `al2023provided.al2023`\n    - Handler: `bootstrap`\n    - IAM Role: Use the IAM Role created earlier\n    - Environment Variables:\n        - `KMS_KEY_ID`: KMS key ID for decrypting OPA policy\n        - `POLICY_PATH`: S3 path to OPA policy\n    - Code: Upload the ZIP archive\n    - Permissions: Allow Cognito to invoke the Lambda function\n- Configure Cognito to send Custom Email Sender events to the Lambda function\n    - Configure the Cognito to use the same KMS key for encryption","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcruxstack%2Fcognito-custom-message-sender-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcruxstack%2Fcognito-custom-message-sender-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcruxstack%2Fcognito-custom-message-sender-go/lists"}