honyakutter-ts
This is an application that translates text entered in Japanese into English and tweets it, defined using AWS CDK v2 (TypeScript) and using AWS Step Functions to connect the translation and tweeting processes.
Preparation
-
Check your AWS CDK version.
cdk --version
If you have not installed it, please use the following command to install it.
npm install -g aws-cdk
This application is intended for use with AWS CDK
v2.0.0
or higher. -
Check your Go version
go version
This application is intended for use with Go 1.17.
-
Getting Twitter API's some tokens.
⚠️ You will need the Twitter API key and secret, as well as the access token and access token secret. Please create an app on the Twitter Developer page and obtain each token. -
Create
.env
file.cp .env.sample .env
And, replace values of each environment variables.
-
Load environment variables.
source .env
Build
-
Build Translate Lambda Function
make build-translate
-
Build Tweet Lambda Function
make build-tweet
Deploying
-
bootstrap (If you haven't done so already)
cdk bootstrap
-
Build Lambda functions
make build
-
Load environment values
make load-env
-
Generate CFn template
cdk synth
-
deploy
cdk deploy
Testing
Manual execution
Execute Lambda functions and Step Functions state machine manually by using AWS CLI.. (The latest versions at the time of this writing are v2.4.4
and 1.22.18
.)
Translate Lambda Function
aws lambda invoke \
--function-name honyakutter-ts-translate-function \
--invocation-type RequestResponse \
--region ap-northeast-1 \
--payload fileb://testdata/translate_lambda_payload.json \
out && cat out
Tweet Lambda Function
aws lambda invoke \
--function-name honyakutter-ts-tweet-function \
--invocation-type Event \
--region ap-northeast-1 \
--payload fileb://testdata/tweet_lambda_payload.json \
out
Start state machine
-
Get state machine ARN
STATEMACHINE_ARN=$( aws stepfunctions list-state-machines \ --query "stateMachines[?name=='honyakutter-ts-translate-tweet-state-maschine'].stateMachineArn" \ --output text ) && echo "${STATEMACHINE_ARN}"
-
execute
aws stepfunctions start-execution \ --state-machine-arn "${STATEMACHINE_ARN}" \ --input file://testdata/statemachine_input.json