Skip to content
Merged
Changes from 1 commit
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
35 changes: 12 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 @@ -287,6 +272,10 @@ func (c *client) updateFunctionConfiguration(ctx context.Context, fm FunctionMan
Environment: &types.Environment{
Variables: fm.Spec.Environments,
},
VpcConfig: &types.VpcConfig{
SecurityGroupIds: fm.Spec.VPCConfig.SecurityGroupIDs,
SubnetIds: fm.Spec.VPCConfig.SubnetIDs,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check nullity for fm.Spec.VPCConfig before call to its fields

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it.

}
// For zip packing Lambda function code, allow update the function handler
// on update the function's manifest.
Expand Down