amazon-web-services - c# 中用于 API 网关 websockets 的 aws CDK 构造
问题描述
我正在使用 AWS CDK 为 API 网关 websocket 构建堆栈。 我可以在这里看到这个文档
但它没有提供任何明确的解释,用于网络套接字的构造。有人可以帮助我正确构造用于 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)
我从某人对示例文档所做的 PR 那里获得了这些信息: https ://github.com/aws-samples/aws-cdk-examples/pull/325/files
我仍在尝试这个,但至少在最新版本的 CDK 中,你可以找到使用过的函数和类。
推荐阅读
- visual-studio-code - 如何纠正 Visual Studio Code 中的键定义?
- pine-script - 将 Pine Script Trailing Stop 转换为 version4
- c# - 如何使用 libphonenumber 查找电话号码?
- swiftui - 使用 SwiftUI。我的滑块/侧边菜单在单击时会启动新视图,但单击
按钮,现在所有选项都“死”了 - formal-verification - 在 Dafny 的 Ensure 子句中调用另一个引理
- javascript - 如何在 Puppeteer 中实现 page.type()?
- html - 如何避免过渡和变换结合时对“悬停”的“抖动效应”?
- python - 如何将数据框列对转换为单个字典映射?
- html - 将 div 固定到页面中心,但调整大小时不会溢出
- node.js - Node.js 使用 AWS EC2 IAM 角色凭证获取签名 URL