【问题标题】:How to deploy new Lambda functions to Stage of existing RestApi?如何将新的 Lambda 函数部署到现有 Rest Api 的 Stage?
【发布时间】:2021-04-17 06:06:39
【问题描述】:

所以,我遇到了很多线程,但没有一个能解决我的问题。 我正在尝试将 Lambda 函数部署到具有现有 DEV 阶段的现有 RestApi。我的 API 是这样构建的:

this.RestAPIDev = new gw.RestApi(this, 'StagingGatewayDev', {
  restApiName: 'gateway-DEV',
  deploy: true,
  deployOptions: {
    stageName: 'DEV',
    description: 'DEV Stage',
    variables: { ALIAS: 'DEV' },
  }
});

Lambda 堆栈在其自己的存储库中分离,包括管道和 lambda 代码。我正在尝试通过添加资源和方法将这些 Lambda 函数部署到这个现有网关,并假设因为我在网关上设置了deploy:true,它将自行部署。 所以这里是 Lambda 堆栈:

const restApi = gw.RestApi.fromRestApiAttributes(this, 'RestApi', {
  restApiId: props.restApiId,
  rootResourceId: props.restApiRoot,
});

const authenticate = new lambda.Function(this, 'AuthenticateFunction', {
  code: this.lambdaCode, // is a property
  runtime: lambda.Runtime.NODEJS_12_X,
  handler: 'src/api/authenticate.handler',
  description: 'API: Authenticates the token',
  role: <executionRole>, // is a property
});

const authenticateAlias = new lambda.Alias(this, 'AuthenticateAlias', {
  aliasName: 'DEV',
  version: new lambda.Version(this, 'AuthenticateVersion', {
    lambda: authenticate,
  }),
});

restApi.root.addResource('authenticate').addMethod(
  'POST',
  new gw.LambdaIntegration(authenticateAlias, {}),
); 

但舞台选项卡上没有更新...

我也尝试了创建新部署和阶段的解决方案,但收到此阶段已存在的错误(我当然知道)。我还尝试创建一个新的部署并向其中添加 deployment.resources.stageName,但这不适用于我的 CDK 版本。

这有什么线索吗?

提前致谢!

【问题讨论】:

    标签: typescript aws-cdk api-gateway


    【解决方案1】:

    我相信在您定义 API 的堆栈中创建阶段并完成部署。在 lambda 堆栈中不执行新部署。

    我建议你不要将 API 导入到你的 lambda 堆栈中,而是将 lambda 导入到你的 API 堆栈中,并在 API 堆栈中定义由 lambda 支持的资源。

    【讨论】:

    • 这可能是一种解决方案,但两个堆栈完全分开并存储在不同的存储库中。我需要导入整个 lambda 堆栈。
    猜你喜欢
    • 2019-10-18
    • 2023-02-21
    • 2018-03-29
    • 1970-01-01
    • 2020-11-02
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 2020-06-21
    相关资源
    最近更新 更多