DaaS / Products / Bidirectional DingTalk-Lark ECS Provisioning Loop

Bidirectional DingTalk-Lark ECS Provisioning Loop

DingTalk or Lark approval events (e.g., new hire onboarding, resource request) flow into EventBridge, which triggers ECS Cloud Assistant provisioning scripts, then routes completion status and audit results back to DingTalk/Lark group chats as notifications — forming a full request-to-confirmation workflow.

Products involved

Scenario

Developers use this bidirectional loop to automate infrastructure provisioning triggered by HR or IT approval workflows in DingTalk or Lark. It eliminates manual ticket routing by capturing approval payloads, executing remote provisioning scripts on ECS instances, and pushing real-time completion status and audit logs back to the originating group chat.

Integration steps

  1. Configure Collaboration Webhook: In DingTalk/Lark, create a custom bot and extract the HTTPS webhook URL. Set the bot to POST JSON approval payloads to a secure ingress endpoint.
  2. Create EventBridge HTTP API Source: Use eb-integrate-events to provision a custom event source. Map the inbound webhook to a CloudEvents schema:
  3. ``json {"source": "dingtalk.approval", "detail-type": "ProvisionRequest", "detail": {"emp_id": "E123", "role": "devops"}} ``

  4. Define EventBridge Rule & ECS Target: Create a rule matching $.source == "dingtalk.approval". Set the target to ACS::ECS::RunCommand with the following target config:
  5. ``json {"CommandId": "c-uf6d8f...", "InstanceIds": ["i-uf6abc..."], "Timeout": 300} ``

  6. Deploy Provisioning Script: Upload /opt/provision.sh to the target Alinux ECS instance. The script must parse {{.detail.emp_id}}, install dependencies, create users, and exit with 0 on success.
  7. Execute via Cloud Assistant: Trigger the workflow using ecs-execute-instances:
  8. ``bash aliyun ecs InvokeCommand --CommandId c-uf6d8f... --InstanceId i-uf6abc... --Parameters '{"emp_id":"E123","role":"devops"}' ``

  9. Route Completion Back: Configure a second EventBridge rule to match $.detail.InvocationStatus == "Success". Set its target to an HTTP POST action that calls the DingTalk/Lark webhook with the audit payload.

Architecture

DingTalk/Lark pushes approval payloads via HTTPS to an EventBridge HTTP API event source. EventBridge evaluates a pattern-matching rule and routes the event to the ECS Cloud Assistant target. Cloud Assistant securely executes the shell script on the designated Alinux ECS instance via the acs:ecs:RunCommand API. Upon completion, Cloud Assistant emits an InvocationResult event back to EventBridge. A secondary rule matches this completion event and triggers an HTTP POST to the original DingTalk/Lark webhook, closing the loop with real-time status.

Prerequisites

Common pitfalls

Typical questions

FAQ

Q: How does the bidirectional DingTalk or Lark ECS provisioning workflow operate? A: The workflow routes DingTalk or Lark approval events into EventBridge to trigger ECS Cloud Assistant provisioning scripts, then sends the completion status and audit results back to the respective group chats. This creates a full request-to-confirmation cycle that automates processes like new hire onboarding or resource requests.