This is an application that translates text entered in Japanese into English and tweets it, defined using AWS CDK v2 (golang) and using AWS Step Functions to connect the translation and tweeting processes.
-
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. -
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 Tweet Lambda Function
cd resources/lambda_functions/tweet \ && GOARCH=amd64 GOOS=linux go build -o bin/main
-
bootstrap
cdk bootstrap
-
Build Lambda functions
make build-tweet
-
Load environment values
source .env
-
Generate CFn template
cdk synth
-
deploy
cdk deploy
go test .
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
.)
aws lambda invoke \
--function-name honyakutter-go-tweet-function \
--invocation-type Event \
--region ap-northeast-1 \
--payload fileb://testdata/tweet_lambda_payload.json \
out
-
Get state machine ARN
STATEMACHINE_ARN=$( aws stepfunctions list-state-machines \ --query "stateMachines[?name=='honyakutter-go-translate-tweet-state-machine'].stateMachineArn" \ --output text ) && echo "${STATEMACHINE_ARN}"
-
execute
aws stepfunctions start-execution \ --state-machine-arn "${STATEMACHINE_ARN}" \ --input file://testdata/statemachine_input.json