I'm using AWS CDK to build stack for API gateway websockets. I can see this documentation here
but it does not provide any clear explanation which on construct to use for web sockets. can someone help me with right construct to use for websockets.
I'm using AWS CDK to build stack for API gateway websockets. I can see this documentation here
but it does not provide any clear explanation which on construct to use for web sockets. can someone help me with right construct to use for websockets.
Still today the CDK team has not published an easy-to-use API like other more common AWS components, hence the lack of any documentation in this regard.
Currently, you could use lower-level constructs to achieve the result, or handle the WS management outside of the CDK environment via CLI, a script, or the web console.
If want to go over using some lower-level constructs while waiting for the CDK to reach a better stage in relation to Websockets APIs here is a little example written with TypeScript:
// Handle your other resources like roles, lambdas, and dependencies
// ...
// Example API definition
const api = new CfnApi(this, name, {
name: "ChatAppApi",
protocolType: "WEBSOCKET",
routeSelectionExpression: "$request.body.action",
});
// Example lambda integration
const connectIntegration = new CfnIntegration(this, "connect-lambda-integration", {
apiId: api.ref,
integrationType: "AWS_PROXY",
integrationUri: "arn:aws:apigateway:" + config["region"] + ":lambda:path/2015-03-31/functions/" + connectFunc.functionArn + "/invocations",
credentialsArn: role.roleArn,
});
// Example route definition
const connectRoute = new CfnRoute(this, "connect-route", {
apiId: api.ref,
routeKey: "$connect",
authorizationType: "NONE",
target: "integrations/" + connectIntegration.ref,
});
// Finishing touches on the API definition
const deployment = new CfnDeployment(this, `${name}-deployment`, {
apiId: api.ref
});
new CfnStage(this, `${name}-stage`, {
apiId: api.ref,
autoDeploy: true,
deploymentId: deployment.ref,
stageName: "dev"
});
const dependencies = new ConcreteDependable();
dependencies.add(connectRoute)
I got this information from a PR someone made to the samples documentation: https://github.com/aws-samples/aws-cdk-examples/pull/325/files
I'm still experimenting with this, but at the very least in the latest version of the CDK, you can find used functions and classes.