kal*_*eni 0 amazon-web-services aws-api-gateway aws-sdk-net
我正在使用 AWS CDK 为 API 网关 websocket 构建堆栈。 我可以在这里看到这个文档
但它没有提供任何明确的解释,在构造上用于 Web 套接字。有人可以帮助我使用正确的构造来用于 websockets。
直到今天,CDK 团队还没有像其他更常见的 AWS 组件那样发布易于使用的 API,因此缺乏这方面的任何文档。
目前,您可以使用较低级别的构造来实现结果,或者通过 CLI、脚本或 Web 控制台处理 CDK 环境之外的 WS 管理。
如果想在等待 CDK 达到与 Websockets API 相关的更好阶段的同时使用一些较低级别的构造,这里有一个用 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)
Run Code Online (Sandbox Code Playgroud)
我从某人对示例文档所做的 PR 中获得了此信息:https : //github.com/aws-samples/aws-cdk-examples/pull/325/files
我仍在对此进行试验,但至少在最新版本的 CDK 中,您可以找到使用过的函数和类。
| 归档时间: |
|
| 查看次数: |
796 次 |
| 最近记录: |