I am using the code below to update a secret in Amazon's secret manager service. Shortly after I update the secret value, I retrieve the secret from AWS, and it isn't the most recently updated value. The code below doesn't throw an exceptions. I am looking for best practices on how to confirm an update to AWS secret manager is successful.
public void updateSecretValue(String fullAwsKey, String keyValue) {
UpdateSecretRequest updateSecretRequest = new UpdateSecretRequest ().withSecretId(fullAwsKey);
updateSecretRequest.setSecretString(keyValue);
AWSSecretsManager client = buildAWSSecretsManager();
try {
performUpdate(updateSecretRequest, client);
} catch (SdkClientException e) {
throw new RuntimeException(e);
} finally {
client.shutdown();
}
}
protected void performUpdate(UpdateSecretRequest updateSecretRequest, AWSSecretsManager client) {
boolean processed = false;
int tryCount = 0;
while (!processed) {
UpdateSecretResult result = client.updateSecret(updateSecretRequest);
if (result.getSdkHttpMetadata().getHttpStatusCode() == 200) {
processed = true;
} else {
tryCount++;
if (tryCount >= 5) {
throw new RuntimeException("performUpdate, unable to update secret: " + result.toString());
}
}
}
}