Home > database >  Automate update configuration of Lambda function
Automate update configuration of Lambda function

Time:06-05

My lambda function's configuration(mainly environment variables, concurrency) need to update frequently. I want to automate this process of updating the lambda function. My initial idea is to use Jenkins job and another lambda function for auto-updating my lambda function. Any suggestions.

CodePudding user response:

AWS CodePipeline will do what you need and is what I use for my serverless services.

https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-serverlessrepo-auto-publish.html

CodePudding user response:

What you're looking for is CICD for your lambda. You can use Jenkins but that comes with extra maintenance & operational overhead.

I don't know your situation, if this is for a personal project or a home lab, but if you need a native solution then AWS CodePipeline is your best bet.

Or if you are using Github, you can enable Github Actions to update your functions upon merge events.

CodePudding user response:

It sounds to me like whatever your CI/CD system is (be it Jenkins, GitLab CI etc.), you need to address the problem at a different level.

Depending on where the "source of truth" for the environment variables is, I think CloudFormation, CDK or Terraform would address your use case. You would switch from imperative infrastructure definitions to declarative infrastructure.

Taking an example with CDK, your Lambda could look like this (also see CDK documentation):

const fn = new lambda.Function(this, 'MyFunction', {
  runtime: lambda.Runtime.NODEJS_16_X,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
  environment: {
    A: 'hello',
    B: 'world',
  },
});

Once you have an infrastructure package set up, you can configure your CI/CD system to deploy that infrastructure.

  • Related