awslabs / aws-saas-boost

AWS SaaS Boost is a ready-to-use toolset that removes the complexity of successfully running SaaS workloads in the AWS cloud.
Apache License 2.0
957 stars 188 forks source link

Update scripts must not fail if Lambda function does not already exist. #480

Closed PoeppingT closed 1 year ago

PoeppingT commented 1 year ago

When updating from older versions of SaaS Boost to newer ones, we rely on each Lambda function's update.sh script to build the code and update any relevant Lambda functions in the AWS account. If any of these update.sh scripts fail, an entire SaaS Boost update will fail, since it assumes something has gone wrong with building or uploading that code.

However, in the case we add a new Lambda function, the existing Lambda function may not already exist until the CloudFormation stack is updated, which is something the Installer executes after running each update.sh script. This change makes these update scripts not fail in that case.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

PoeppingT commented 1 year ago

For the services' update scripts, we may have to add --no-paginate

To test this I created 1000 lambda functions, and it looks like we don't need to do anything special with pagination for services.

With 1000 functions labelled example{0...1000}

aws lambda list-functions --query 'Functions[?ends_with(FunctionName, `"0"`)] | [].FunctionName' --output text | sed 's/\t/\n/g' | wc -l
     101

and

aws lambda list-functions --query 'Functions[?starts_with(FunctionName, `example`)] | [].FunctionName' --output text | sed 's/\t/\n/g' | wc -l
    1001

Not entirely sure why the normal service update scripts work without the sed command, but I'm willing to take that at face value. I agree that it might make sense to switch to get-function for performance reasons, but for reference scanning 1000 functions only takes ~2 seconds, which is far less than the amount of time it takes to build the code and update each function anyway, so I would argue it isn't worth the extra effort of doing error checking for the minimal performance gain.