项目作者: zxkane

项目描述 :
The dingtalk callback powered by AWS lambda, Dynamodb.
高级语言: Kotlin
项目地址: git://github.com/zxkane/dingtalk-callback-on-aws.git
创建时间: 2019-03-25T08:11:15Z
项目社区:https://github.com/zxkane/dingtalk-callback-on-aws

开源协议:

下载


A Dingtalk(钉钉) callback on AWS

Build Status

The program provides a HTTP API endpoint to receive kinds of dingtalk callback events and persist them in AWS DynamoDB, including BPM events, Organization events and so on.

It is written by Kotlin and leverages below AWS services,

How to deploy this program

Prerequisites

  1. Get the corpid of your dingtalk’s organization in open dev platform
  2. Create secure parameters named DD_TOKEN, DD_AES_TOKEN and DD_CORPID(from step 1) in Systems Manager
  3. Create a S3 bucket(say my-deploy-bucket) for deployment
  4. [Optional] Install and configure SAM CLI for local deployment

Build, Test and package

  1. # build the source
  2. ./gradlew build

Deploy via SAM cli

  1. # package the lambda functions
  2. sam package --output-template-file packaged.yaml \
  3. --s3-bucket my-deploy-bucket --template-file template-sam.yaml
  4. # deploy the lambda function, api gateway, dybnamodb
  5. sam deploy --template-file ./packaged.yaml \
  6. --stack-name my-dingtalk-callback --capabilities CAPABILITY_IAM

Deploy via serverless framework

  1. sls deploy

Deploy via Code pipeline

  1. Put the github person token to codepipeline.json
  2. Set the s3 bucket name in codepipeline.json
  3. Set any parameter in codepipeline.json if necessary, such as app name, repo name and branch name
  4. Create a CI/CD pipeline in CodePipeline via below command, which can be continously triggered by new commits of this repo then deploy lambda HTTP endpoint
    1. aws cloudformation create-stack --stack-name dingtalk-mycorp --template-body file://codepipeline.yml --parameters file://codepipeline.json --capabilities CAPABILITY_NAMED_IAM

Post deployment actions

  1. Get id of api gateway of AWS created by above deployment
  2. Use dingtalk API to register/update this serverless API gateway endpoint as callback of dingtalk events.

For example,

  1. curl -X POST \
  2. 'https://oapi.dingtalk.com/call_back/update_call_back?access_token=<your token>' \
  3. -H 'Content-Type: application/json' \
  4. -d '{
  5. "call_back_tag": [
  6. "bpms_task_change",
  7. "bpms_instance_change"
  8. ],
  9. "token": "<token created in prerequisites step 2>",
  10. "aes_key": "<aes token created in prerequisites step 2>",
  11. "url": "https://<id of api gateway created by above deployment>.execute-api.<your region>.amazonaws.com/v1/dingtalk"
  12. }'

Spring Cloud Function version

I also port this lambda function to use Spring Cloud Function as lambda framework, you can checkout this branch if your’re interested.