31
31
import java .util .function .Function ;
32
32
import java .util .function .Supplier ;
33
33
import javax .annotation .Nonnull ;
34
+ import lombok .Getter ;
35
+ import lombok .Setter ;
34
36
import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
35
37
import software .amazon .awssdk .auth .credentials .AwsSessionCredentials ;
36
38
import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
@@ -66,6 +68,9 @@ public class AmazonWebServicesClientProxy implements CallChain {
66
68
private final LoggerProxy loggerProxy ;
67
69
private final DelayFactory override ;
68
70
private final WaitStrategy waitStrategy ;
71
+ @ Getter
72
+ @ Setter
73
+ private Boolean invokedByCfn ;
69
74
70
75
public AmazonWebServicesClientProxy (final LoggerProxy loggerProxy ,
71
76
final Credentials credentials ,
@@ -77,13 +82,14 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
77
82
final Credentials credentials ,
78
83
final Supplier <Long > remainingTimeToExecute ,
79
84
final DelayFactory override ) {
80
- this (loggerProxy , credentials , override , WaitStrategy .newLocalLoopAwaitStrategy (remainingTimeToExecute ));
85
+ this (loggerProxy , credentials , override , WaitStrategy .newLocalLoopAwaitStrategy (remainingTimeToExecute ), null );
81
86
}
82
87
83
88
public AmazonWebServicesClientProxy (final LoggerProxy loggerProxy ,
84
89
final Credentials credentials ,
85
90
final DelayFactory override ,
86
- final WaitStrategy waitStrategy ) {
91
+ final WaitStrategy waitStrategy ,
92
+ final Boolean invokedByCfn ) {
87
93
this .loggerProxy = loggerProxy ;
88
94
BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials (credentials .getAccessKeyId (),
89
95
credentials .getSecretAccessKey (),
@@ -95,6 +101,7 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
95
101
this .v2CredentialsProvider = StaticCredentialsProvider .create (awsSessionCredentials );
96
102
this .override = Objects .requireNonNull (override );
97
103
this .waitStrategy = Objects .requireNonNull (waitStrategy );
104
+ this .invokedByCfn = invokedByCfn ;
98
105
}
99
106
100
107
public <ClientT > ProxyClient <ClientT > newProxy (@ Nonnull Supplier <ClientT > client ) {
@@ -331,6 +338,15 @@ public Completed<RequestT, ResponseT, ClientT, ModelT, CallbackT> handleError(Ex
331
338
do {
332
339
try {
333
340
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
+
334
350
} catch (RetryableException e ) {
335
351
break ;
336
352
} catch (Exception e ) {
0 commit comments