Pragmatically update an AWS Lambda VPC info

  •  

    I'm looking for an example code that uses boto3 that can update an existing AWS Lambda function's VPC info. I need to write a code so that every time the lambda function is redeployed, the python script will be triggered and it will update the lambda function that just got deployed. I don't want to manually update the lambda function since there are times when our developers deploy it multiple times a day.

    I have to configure the lambda function to use our vpc so that when it connects to our hospital partners, packets or api request we sent will always come from the same ip address.

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • It sounds like you want to be able to dynamically deploy a lambda, updating its configuration at deploy time. If you were to create a CloudFormation "stack" that defines your lambda (its code, IAM policies, SNS/SQS/S3 hooks, VPC configuration, etc.), you could then use the AWS CLI to deploy the CloudFormation stack, and you're good to go. It's not quite that easy, but that's the gist of it.

    A CloudFormation stack is just a JSON or YAML file, and using the CLI or your own processes/scripts, you can dynamically construct a CloudFormation stack (build a JSON or YAML file) and then deploy it. That's what we do where I work, we've got an Azure Devops pipeline that uses a CloudFormation "template" that is parameterized, and our deployment pipeline merges the parameterized file with our deployment-specific details (parameters and such) to create a final "stack" that we then deploy with the CLI.

    Assuming CloudFormation can handle VPC configuration (and I think it can) then I expect the parts you are going to need are a parameterized CloudFormation "template" (you can create a template with parameter substitutions and such, e.g. your VPC configuration) and then a script that uses the AWS CLI (or your own script code) to merge your specific VPC settings/parameters into your template to generate a CloudFormation stack that you can then deploy with the AWS CLI.

    I'm not sure I can help you much more than this, I'm very much an AWS n00b myself, you'll have to research CloudFormation and the AWS CLI on your own (Google AWS CLI and CloudFormation, there's lots of info and some of it is even useful). I'm pretty sure you can accomplish this, and maybe someone else can come along and give you some more useful details.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply