Skip to content

Commit

Permalink
fix(bedrockagent): set Bedrock Datasource data deletion policy to RET…
Browse files Browse the repository at this point in the history
…AIN before deleting it
  • Loading branch information
npellegrin committed Nov 24, 2024
1 parent 1611bd9 commit cca02de
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions resources/bedrock-agent-datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,32 @@ func (r *BedrockDataSource) Properties() types.Properties {
}

func (r *BedrockDataSource) Remove(_ context.Context) error {
_, err := r.svc.DeleteDataSource(&bedrockagent.DeleteDataSourceInput{
// Must set retention to RETAIN to be able to delete datasource when data is already removed
// Reference: https://github.com/ekristen/aws-nuke/issues/431
current, err := r.svc.GetDataSource(&bedrockagent.GetDataSourceInput{
DataSourceId: r.ID,
KnowledgeBaseId: r.KnowledgeBaseID,
})
if err != nil {
return err
}
_, err = r.svc.UpdateDataSource(&bedrockagent.UpdateDataSourceInput{
DataDeletionPolicy: aws.String(bedrockagent.DataDeletionPolicyRetain),
DataSourceConfiguration: current.DataSource.DataSourceConfiguration,
DataSourceId: r.ID,
Description: current.DataSource.Description,
KnowledgeBaseId: r.KnowledgeBaseID,
Name: current.DataSource.Name,
ServerSideEncryptionConfiguration: current.DataSource.ServerSideEncryptionConfiguration,
VectorIngestionConfiguration: current.DataSource.VectorIngestionConfiguration,
})
if err != nil {
return err
}
_, err = r.svc.DeleteDataSource(&bedrockagent.DeleteDataSourceInput{
DataSourceId: r.ID,
KnowledgeBaseId: r.KnowledgeBaseID,
})

return err
}

Expand Down

0 comments on commit cca02de

Please sign in to comment.