in src/tasks/LambdaDeployFunction/TaskOperations.ts [86:153]
private async updateFunction(): Promise<string> {
console.log(tl.loc('UpdatingFunctionConfiguration', this.taskParameters.functionName))
// Cannot update code and configuration at the same time. As 'publish' option is
// only available when updating the code, do that last
try {
const updateConfigRequest: Lambda.UpdateFunctionConfigurationRequest = {
FunctionName: this.taskParameters.functionName,
Handler: this.taskParameters.functionHandler,
Role: await SdkUtils.roleArnFromName(this.iamClient, this.taskParameters.roleARN),
MemorySize: this.taskParameters.memorySize,
Timeout: this.taskParameters.timeout,
Runtime: this.taskParameters.runtime,
KMSKeyArn: this.taskParameters.kmsKeyARN,
DeadLetterConfig: {
TargetArn: this.taskParameters.deadLetterARN
}
}
if (this.taskParameters.description) {
updateConfigRequest.Description = this.taskParameters.description
}
if (this.taskParameters.environment) {
updateConfigRequest.Environment = {}
updateConfigRequest.Environment.Variables = SdkUtils.getTagsDictonary(this.taskParameters.environment)
}
if (this.taskParameters.securityGroups) {
updateConfigRequest.VpcConfig = {
SecurityGroupIds: this.taskParameters.securityGroups,
SubnetIds: this.taskParameters.subnets
}
}
if (this.taskParameters.layers && this.taskParameters.layers.length > 0) {
updateConfigRequest.Layers = this.taskParameters.layers
}
if (this.taskParameters.tracingConfig && this.taskParameters.tracingConfig !== 'XRay') {
updateConfigRequest.TracingConfig = {
Mode: this.taskParameters.tracingConfig
}
}
const response = await this.lambdaClient.updateFunctionConfiguration(updateConfigRequest).promise()
if (!response.FunctionArn) {
throw new Error(tl.loc('NoFunctionArnReturned'))
}
await this.waitForStatus(FUNCTION_UPDATED)
// Update tags if we have them
const tags = SdkUtils.getTagsDictonary<Lambda.Tags>(this.taskParameters.tags)
if (tags && Object.keys(tags).length > 0) {
try {
const tagRequest: Lambda.TagResourceRequest = {
Resource: response.FunctionArn,
Tags: tags
}
await this.lambdaClient.tagResource(tagRequest).promise()
} catch (e) {
tl.warning(`${e}`)
}
}
return await this.updateFunctionCode()
} catch (err) {
throw new Error(`Error while updating function configuration: ${err}`)
}
}