【问题标题】:aws CDK construct in c# for API gateway websocketsc# 中用于 API 网关 websockets 的 aws CDK 构造
【发布时间】:2020-08-19 23:47:58
【问题描述】:

我正在使用 AWS CDK 为 API 网关 websocket 构建堆栈。 I can see this documentation here

但它没有提供任何明确的解释,用于 web 套接字的构造。有人可以帮助我正确构造用于 websockets。

【问题讨论】:

    标签: amazon-web-services aws-api-gateway aws-sdk-net


    【解决方案1】:

    直到今天,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 中,你可以找到使用过的函数和类。

    【讨论】:

      猜你喜欢
      • 2019-03-16
      • 2019-11-10
      • 2020-09-07
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 2020-05-20
      相关资源
      最近更新 更多