Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

typescript - How to deploy new Lambda functions to Stage of existing RestApi?

So, I cam across a lot of threads, but none of them solved my problem. I am trying to deploy Lambda functions to an existing RestApi with an existing DEV-Stage. My API is build like this:

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

The Lambda Stack is separated in its own repository including a pipeline and the lambda code. I am trying to deploy these Lambda functions to this existing gateway by adding resources and methods and assume that because i set deploy:true on the gateway, it will get deployed by itself. So here is the Lambda Stack:

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, {}),
); 

But no update on the Stage Tab...

I have also tried the solution to create a new Deployment and Stage, but got the error that this stage already exists (Sure I know). I also tried to create a new Deployment and add deployment.resources.stageName to it, but this isn't available for my CDK version.

Any clue on this?

Thanks in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I believe that stage is created and deployment done in the stack where you define you API. In the lambda stack new deployment is not performed.

I suggest you to not import API into your lambda stack, but import lambda into your API stack and define resources backed by the lambda in the API stack.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...