Sample project deploying a TypeScript-based Restate service to AWS Lambda using the AWS Cloud Development Kit (CDK). The stack uses the Restate CDK constructs library to create an EC2-hosted Restate server in AWS, and to register the service with this Restate environment.
For more information on CDK, please see Getting started with the AWS CDK.
- CDK app entry point
lambda-ts-cdk.ts
- CDK stack consisting of a Lambda function and providing Restate service registration
- TypeScript Lambda handler
-
Via the CLI:
restate example typescript-hello-world-lambda-cdk && cd typescript-hello-world-lambda-cdk
-
Via git clone:
git clone git@github.com:restatedev/examples.git cd examples/templates/typescript-lambda-cdk
-
Via
wget
:wget https://github.com/restatedev/examples/releases/latest/download/typescript-hello-world-lambda-cdk.zip && unzip typescript-hello-world-lambda-cdk.zip -d typescript-hello-world-lambda-cdk && rm typescript-hello-world-lambda-cdk.zip
Pre-requisites:
- npm
- AWS account, bootstrapped for CDK use
- valid AWS credentials with sufficient privileges to create the necessary resources
- an existing Restate Cloud environment (environment id + API key)
Install npm dependencies:
npm install
To deploy the stack, export the Restate Cloud environment id and API key, and run cdk deploy
:
export RESTATE_ENV_ID=env_... RESTATE_API_KEY=key_...
npx cdk deploy
You can send a test request to the Restate ingress endpoint to call the newly deployed service:
You can send a test request to the Restate cluster ingress endpoint to call the newly deployed service:
curl -k ${restateIngressUrl}/Greeter/greet \
-H "Authorization: Bearer $RESTATE_API_KEY" \
-H 'content-type: application/json' -d '"Restate"'
Note the single-quotes around the input to prevent the shell from interpreting the inner quotes - the request must be a valid JSON string value.
npm run build
compile the Lambda handler and synthesize CDK deployment artifactsnpm run deploy
perform a CDK deploymentnpm run destroy
delete the stack and all its resources