classmethod / gradle-aws-plugin

Gradle plugin to manage Amazon Web Services
276 stars 132 forks source link

Updating multiple Lambda Functions #121

Open szaluk opened 6 years ago

szaluk commented 6 years ago

I am trying to write a task that can update multiple Lambda functions with the same S3File. Here is the code I am using:

def devLambdaFunctionNames = ["function1Dev", "function2Dev", "function3Dev"]
def prodLambdaFunctionNames = ["function1Prod", "function2Prod", "function3Prod"]

task updateLambdas(type: AWSLambdaUpdateFunctionCodeTask, dependsOn: uploadArtifactToS3) {
    doFirst {
        if (apiStage.equalsIgnoreCase("dev")) {
            for(String lambdaFunctionName : devLambdaFunctionNames) {
                logger.lifecycle("LAMBDA: Updating function ${lambdaFunctionName} with S3:${bucket}/${artifactName}..")

                functionName = lambdaFunctionName

                def artifact = new S3File()
                artifact.setBucketName(bucket)
                artifact.setKey(artifactName)

                s3File = artifact
            }
        } else {
            for(String lambdaFunctionName : prodLambdaFunctionNames) {
                logger.lifecycle("LAMBDA: Updating function ${lambdaFunctionName} with S3:${bucket}/${artifactName}..")

                functionName = lambdaFunctionName

                def artifact = new S3File()
                artifact.setBucketName(bucket)
                artifact.setKey(artifactName)

                s3File = artifact
            }
        }
    }
}

What seems to be happening is only the last Lambda function is the list is getting updated - either function3Dev or function3Prod depending on what apiStage is set to. How can I do this so I can iterate over a list of Lambda functions and update them in one task call?

Thanks, Steve