How to Trigger an AWS Lambda from Kinesis
How to Trigger an AWS Lambda from Kinesis
先建立資料夾拉~~~
mkdir how-to-trigger-lambda-from-kinesis
cd how-to-trigger-lambda-from-kinesis
npx cdk init app --language typescript
安裝 kinesis & lambda
npm i @aws-cdk/aws-kinesis
npm i @aws-cdk/aws-lambda
npm i @aws-cdk/aws-lambda-event-sources
新增一個檔案.env
touch .env
1 | AWS_ACCOUNT_ID=1234567890123 |
修改 how-to-trigger-lambda-from-kinesis.ts
1 |
|
修改 how-to-trigger-lambda-from-kinesis-stack.ts
1 | import * as cdk from '@aws-cdk/core'; |
新增 src/index.js 撰寫一下lambda code (這次來用一下nodejs寫)
1 | exports.handler = async (event) => { |
準備發佈前
cdk bootstrap
⏳ Bootstrapping environment aws://xxxxxxxx/us-east-2…
✅ Environment aws://xxxxxxx/us-east-2 bootstrapped (no changes).
發佈
cdk deploy
test
aws kinesis list-streams
aws kinesis put-record --data "aGVsbG8sIHdvcmxk" --stream-name MyKinesisStream --partition-key pk1