aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.7k stars 3.93k forks source link

aws-lambda-nodejs #12165

Closed smaud closed 1 year ago

smaud commented 3 years ago

:question: General Issue

The Question

aws-lambda-nodejs does not have an example of integration with CI/CD and codeDeploy blue/green/canary pipeline.

Lambda example (https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html?shortFooter=true) requires a Lambda property of code to be present but this is not presented on aws-lambda-nodejs.

  code: this.lambdaCode,

Please provide similar example.

Environment

Other information

redbaron commented 3 years ago

aws-lambda-nodejs module documentation provides comprehensive example how to setup function: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html

Pipeline example can then be ammended to use aws-lambda-nodejs.NodejsFunction instead of lambda.Function. It is also likely you wont need to have a separate Lambda build step, but I haven't tried it myself

sholtomaud commented 3 years ago

Unfortunately the Pipeline example uses the code property of lambda, whereas aws-lambda-nodejs does not have this property and expects a file. If you have an example showing how to put aws-lambda-nodejs into a blue/green CI/CD please post it. Thanks! :)

redbaron commented 3 years ago

I don't have example at hand, but did you try to replace these in lib/lambda-stack.ts:

    this.lambdaCode = lambda.Code.fromCfnParameters();

    const func = new lambda.Function(this, 'Lambda', {
      code: this.lambdaCode,
      handler: 'index.main',
      runtime: lambda.Runtime.NODEJS_10_X,
      description: `Function generated on: ${new Date().toISOString()}`,
    });

    const alias = new lambda.Alias(this, 'LambdaAlias', {
      aliasName: 'Prod',
      version: func.currentVersion,
    });

With:

  const func = new lambda.NodejsFunction(this, 'MyFunction', {
     entry: '/path/to/my/file.ts', // accepts .js, .jsx, .ts and .tsx files
     handler: 'myExportedFunc'
  });

    const alias = new lambda.Alias(this, 'LambdaAlias', {
      aliasName: 'Prod',
      version: func.currentVersion,
    });

As for how to implement Blue/Green deployments with CodePipeline, I think this is more of a question for amazon forum, reddit or support as it is not related to CDK directly.

sholtomaud commented 3 years ago

Yes I did - but how do you get the path to the file if it hasn't been built yet by codebuild??

redbaron commented 3 years ago

My understanding is that it "builds" it for you, that is code resides somewhere within CDK app and aws-lambda-nodejs takes care of packaging it as a zip file and creating Lambda function for you

sholtomaud commented 3 years ago

how would you do blue/green codedeploy?

Mr Sholto Maud

redbaron commented 3 years ago

That's more of a codepipeline question, rather than CDK, I dont use former so can't help much. Maybe other CDK users can share their experience.

sholtomaud commented 3 years ago

Nah, definitely a CDK question.

You need CDK CI/CD to deploy nodejs lambda blue/green.

tim-finnigan commented 1 year ago

This issue hasn't received any activity in a long time. If there are still requests an example then I suggest creating an issue or PR in this repository: https://github.com/aws-samples/aws-cdk-examples/issues.

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

RiFrost commented 1 year ago

@sholtomaud Did you find a solution for this yet? Facing a similar problem, where I want to setup a CI/CD Pipeline where in the deploy stage a lambda Function should be deployt from code which is being build the step before and put into an artifact.

sholtomaud commented 1 year ago

Yes I did. I don't have the code on me however.

enheit commented 11 months ago

I also can't find an example of how to create a CI/CD pipeline with @aws-cdk/aws-lambda-nodejs module. If someone has a link to a resource that explains it, could you please share it?

sholtomaud commented 11 months ago

AWS need to lift their game, its their product.