Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #4560 #4561 #4562

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions pkg/app/piped/platformprovider/lambda/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func (c *client) CreateFunctionFromSource(ctx context.Context, fm FunctionManife
}

func (c *client) UpdateFunction(ctx context.Context, fm FunctionManifest) error {
// UpdateFunctionConfiguration must be called before UpdateFunctionCode.
// Lambda has named by state.
// If Lambda's state is pending, UpdateFunctionConfiguration is failed. This error is explained as a ResourceConflictException.
// ref: https://docs.aws.amazon.com/lambda/latest/dg/troubleshooting-invocation.html
// Update function configuration.
if err := c.updateFunctionConfiguration(ctx, fm); err != nil {
return err
}
// Update function code.
codeInput := &lambda.UpdateFunctionCodeInput{
FunctionName: aws.String(fm.Spec.Name),
Expand All @@ -214,29 +222,6 @@ func (c *client) UpdateFunction(ctx context.Context, fm FunctionManifest) error
return fmt.Errorf("failed to update function code for Lambda function %s: %w", fm.Spec.Name, err)
}

// Update lambda function configuration
// TODO: @sivchari
// I focused on the vpc configuration, now. But, I think we should update all the configuration.
// So, I will update this part later.
if fm.Spec.VPCConfig != nil {
cfgInput := &lambda.UpdateFunctionConfigurationInput{
FunctionName: aws.String(fm.Spec.Name),
VpcConfig: &types.VpcConfig{
SecurityGroupIds: fm.Spec.VPCConfig.SecurityGroupIDs,
SubnetIds: fm.Spec.VPCConfig.SubnetIDs,
},
}
_, err = c.client.UpdateFunctionConfiguration(ctx, cfgInput)
if err != nil {
return fmt.Errorf("failed to update function configuration for Lambda function %s: %w", fm.Spec.Name, err)
}
}

// Update function configuration.
if err = c.updateFunctionConfiguration(ctx, fm); err != nil {
return err
}

// Tag/Untag function if necessary.
return c.updateTagsConfig(ctx, fm)
}
Expand Down Expand Up @@ -293,6 +278,12 @@ func (c *client) updateFunctionConfiguration(ctx context.Context, fm FunctionMan
if fm.Spec.Handler != "" {
configInput.Handler = aws.String(fm.Spec.Handler)
}
if fm.Spec.VPCConfig != nil {
configInput.VpcConfig = &types.VpcConfig{
SecurityGroupIds: fm.Spec.VPCConfig.SecurityGroupIDs,
SubnetIds: fm.Spec.VPCConfig.SubnetIDs,
}
}
_, err = c.client.UpdateFunctionConfiguration(ctx, configInput)
if err != nil {
c.logger.Error("Failed to update function configuration")
Expand Down