Skip to content

Commit

Permalink
Fix for AlreadyExists
Browse files Browse the repository at this point in the history
  • Loading branch information
tvp-1 committed Jul 17, 2024
1 parent b9cfe28 commit 9213b1a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
<java>
<!-- this automatically inserts line breaks, so apply it before eclipse formatter! -->
<importOrder>
<order>com,edu,java,lombok,javax,org,software</order>
<order>com,edu,java,javax,lombok,org,software</order>
</importOrder>
<removeUnusedImports/>
<eclipse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ public void processRequest(final InputStream inputStream, final OutputStream out
if (request.getRequestData().getCallerCredentials() != null) {
awsClientProxy = new AmazonWebServicesClientProxy(this.loggerProxy, request.getRequestData().getCallerCredentials(),
DelayFactory.CONSTANT_DEFAULT_DELAY_FACTORY,
WaitStrategy.scheduleForCallbackStrategy());
WaitStrategy.scheduleForCallbackStrategy(),
request.getStackId() != null);
}

ProgressEvent<ResourceT, CallbackT> handlerResponse = wrapInvocationAndHandleErrors(awsClientProxy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private ProgressEvent<TargetT, CallbackT> processInvocation(final JSONObject raw
if (processedCallerCredentials != null) {
awsClientProxy = new AmazonWebServicesClientProxy(this.loggerProxy, processedCallerCredentials,
DelayFactory.CONSTANT_DEFAULT_DELAY_FACTORY,
WaitStrategy.scheduleForCallbackStrategy());
WaitStrategy.scheduleForCallbackStrategy(), true);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import lombok.Getter;
import lombok.Setter;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
Expand Down Expand Up @@ -66,6 +68,9 @@ public class AmazonWebServicesClientProxy implements CallChain {
private final LoggerProxy loggerProxy;
private final DelayFactory override;
private final WaitStrategy waitStrategy;
@Getter
@Setter
private Boolean invokedByCfn;

public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
final Credentials credentials,
Expand All @@ -77,13 +82,14 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
final Credentials credentials,
final Supplier<Long> remainingTimeToExecute,
final DelayFactory override) {
this(loggerProxy, credentials, override, WaitStrategy.newLocalLoopAwaitStrategy(remainingTimeToExecute));
this(loggerProxy, credentials, override, WaitStrategy.newLocalLoopAwaitStrategy(remainingTimeToExecute), null);
}

public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
final Credentials credentials,
final DelayFactory override,
final WaitStrategy waitStrategy) {
final WaitStrategy waitStrategy,
final Boolean invokedByCfn) {
this.loggerProxy = loggerProxy;
BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(credentials.getAccessKeyId(),
credentials.getSecretAccessKey(),
Expand All @@ -95,6 +101,7 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
this.v2CredentialsProvider = StaticCredentialsProvider.create(awsSessionCredentials);
this.override = Objects.requireNonNull(override);
this.waitStrategy = Objects.requireNonNull(waitStrategy);
this.invokedByCfn = invokedByCfn;
}

public <ClientT> ProxyClient<ClientT> newProxy(@Nonnull Supplier<ClientT> client) {
Expand Down Expand Up @@ -331,6 +338,15 @@ public Completed<RequestT, ResponseT, ClientT, ModelT, CallbackT> handleError(Ex
do {
try {
event = inner.invoke(request, ex, client_, model_, context_);

//
// Ensure that we null out model for AlreadyExists to meet CFN IaC expectations
//
if (event.getErrorCode() == HandlerErrorCode.AlreadyExists
&& AmazonWebServicesClientProxy.this.invokedByCfn) {
event.setResourceModel(null);
}

} catch (RetryableException e) {
break;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.CheckForNull;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.Setter;
import javax.annotation.CheckForNull;
import org.json.JSONObject;
import software.amazon.cloudformation.resource.Serializer;

Expand Down

0 comments on commit 9213b1a

Please sign in to comment.