Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for AlreadyExists #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading