3131import java .util .function .Function ;
3232import java .util .function .Supplier ;
3333import javax .annotation .Nonnull ;
34+ import lombok .Getter ;
35+ import lombok .Setter ;
3436import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
3537import software .amazon .awssdk .auth .credentials .AwsSessionCredentials ;
3638import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
@@ -66,6 +68,9 @@ public class AmazonWebServicesClientProxy implements CallChain {
6668 private final LoggerProxy loggerProxy ;
6769 private final DelayFactory override ;
6870 private final WaitStrategy waitStrategy ;
71+ @ Getter
72+ @ Setter
73+ private Boolean invokedByCfn ;
6974
7075 public AmazonWebServicesClientProxy (final LoggerProxy loggerProxy ,
7176 final Credentials credentials ,
@@ -77,13 +82,14 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
7782 final Credentials credentials ,
7883 final Supplier <Long > remainingTimeToExecute ,
7984 final DelayFactory override ) {
80- this (loggerProxy , credentials , override , WaitStrategy .newLocalLoopAwaitStrategy (remainingTimeToExecute ));
85+ this (loggerProxy , credentials , override , WaitStrategy .newLocalLoopAwaitStrategy (remainingTimeToExecute ), null );
8186 }
8287
8388 public AmazonWebServicesClientProxy (final LoggerProxy loggerProxy ,
8489 final Credentials credentials ,
8590 final DelayFactory override ,
86- final WaitStrategy waitStrategy ) {
91+ final WaitStrategy waitStrategy ,
92+ final Boolean invokedByCfn ) {
8793 this .loggerProxy = loggerProxy ;
8894 BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials (credentials .getAccessKeyId (),
8995 credentials .getSecretAccessKey (),
@@ -95,6 +101,7 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
95101 this .v2CredentialsProvider = StaticCredentialsProvider .create (awsSessionCredentials );
96102 this .override = Objects .requireNonNull (override );
97103 this .waitStrategy = Objects .requireNonNull (waitStrategy );
104+ this .invokedByCfn = invokedByCfn ;
98105 }
99106
100107 public <ClientT > ProxyClient <ClientT > newProxy (@ Nonnull Supplier <ClientT > client ) {
@@ -331,6 +338,15 @@ public Completed<RequestT, ResponseT, ClientT, ModelT, CallbackT> handleError(Ex
331338 do {
332339 try {
333340 event = inner .invoke (request , ex , client_ , model_ , context_ );
341+
342+ //
343+ // Ensure that we null out model for AlreadyExists to meet CFN IaC expectations
344+ //
345+ if (event .getErrorCode () == HandlerErrorCode .AlreadyExists
346+ && AmazonWebServicesClientProxy .this .invokedByCfn ) {
347+ event .setResourceModel (null );
348+ }
349+
334350 } catch (RetryableException e ) {
335351 break ;
336352 } catch (Exception e ) {
0 commit comments