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

AWS::SSM::Parameter resource #159

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

ferozbaig-amzn
Copy link

Development of AWS::SSM::Parameter resource

aws-ssm-parameter/aws-ssm-parameter.json Outdated Show resolved Hide resolved
aws-ssm-parameter/aws-ssm-parameter.json Outdated Show resolved Hide resolved
} else if (hasThrottled(e)) {
ex = new CfnThrottlingException(e);
} else {
ex = new CfnGeneralServiceException(e);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find this Exception in javadoc for AWS::SSM::Parameter Resource. Unable to reproduce this error.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass in bad inputs and check what exceptions are thrown. It might map to InvalidRequest

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Added more exception handling cases.

Copy link

@advaj advaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a lot of deviation between native and this code base.

I have gone through everything except Update. But Create and Update are similar. Can you make the changes requested and when I look at it a second time, I will take a look at Update as well.

"description": "The information about the parameter.",
"minLength": 0,
"maxLength": 1024
"description": "Information about the parameter."
},
"Policies": {
"type": "string",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an object - it can take both a JSON and a String? Can you test this to verify? (Stringification is usually applicable to policies, but please verify it)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFN Doc says Policies is of type String

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried creating it via CLI with Json value instead of String, and faced below error.

Parameter validation failed:
Invalid type for parameter Policies

if (model.getName() == null) {
model.setName(IdentifierUtils.generateResourceIdentifier("CFN",
request.getLogicalResourceIdentifier(),
request.getClientRequestToken(), 40));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you arrive at 40? Also, you dont seem to be truncating the length of the logical resource id. WHy not just use the same function as native. Much easier. (Use the same values too)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted back to native implementation

Comment on lines +68 to +69
.makeServiceCall((putParameterRequest, ssmProxyClient) ->
ssmProxyClient.injectCredentialsAndInvokeV2(putParameterRequest, ssmProxyClient.client()::putParameter))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there are two workflows here:

  1. When the SSM parameter is not of EC2 type - then we just create the SSM parameter.
  2. If it is of EC2 type, then we use versioning.

Where have you handled this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been handled

.makeServiceCall((putParameterRequest, ssmProxyClient) ->
ssmProxyClient.injectCredentialsAndInvokeV2(putParameterRequest, ssmProxyClient.client()::putParameter))
.stabilize((req, response, client, model1, cbContext) -> stabilize(req, response, client, model1, cbContext, logger))
.handleError((req, e, proxy1, model1, context1) -> handleError(req, e, proxy1, model1, context1, logger))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it seems like AlreadyExistsExceptions are swallowed after comparing to check if the resource OOB has identical configuration.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might cause contract test failures though - so we need to call this out. (Office hours item)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we let it pass if the resource exists with identical configuration ? A confirmation would help.

.backoffDelay(getBackOffDelay(model))
.makeServiceCall((putParameterRequest, ssmProxyClient) ->
ssmProxyClient.injectCredentialsAndInvokeV2(putParameterRequest, ssmProxyClient.client()::putParameter))
.stabilize((req, response, client, model1, cbContext) -> stabilize(req, response, client, model1, cbContext, logger))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stabilization is called only for EC2 data types. You seem to be stabilizing even when the type is not EC2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return false;
}
return (response.parameters() != null && response.parameters().get(0).version() == putParameterResponse.version());
} catch (Exception e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle Throttling here. If the exception type is of Throttling, then you can return false and retry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}

protected ProgressEvent<ResourceModel, CallbackContext> handleError(SsmRequest ssmRequest, Exception e, ProxyClient<SsmClient> proxyClient,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Native is handling a lot more errors - look for this -

` private static final Set THROTTLING_ERROR_CODES = ImmutableSet.of(
"ThrottlingException",
"TooManyUpdates");

private static final Set<String> ERROR_CODES_THAT_DEFAULT_TO_RETRIABLE_UNTOUCHED = Sets.union(
        Collections.singleton(HTTP_CONNECTION_TIMEOUT_ERROR_CODE),
        THROTTLING_ERROR_CODES);

private static final Set<String> ERROR_CODES_THAT_DEFAULT_TO_RETRIABLE_TOUCHED = ImmutableSet.of(
        HTTP_TIMEOUT_ERROR_CODE,
        HTTP_FAILURE_ERROR_CODE);`

Copy link
Author

@ferozbaig-amzn ferozbaig-amzn Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's counterpart hasThrottled() has already been implemented which looks for errorCode.

logger.log("Invoking Read Handler");
logger.log("READ ResourceModel: " + model.toString());

return ProgressEvent.progress(model, callbackContext)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify to see if Drift if working for values other than Type/Value? Looks like native is only checking for these 2 attributes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drift does not work for Native. Yes Native only checks for 2 attributes. Current Uluru implementation supports all attributes.

return ProgressEvent.progress(model, callbackContext)
.then(progress -> getParameters(proxy, progress, proxyClient, model, callbackContext, logger))
.then(progress -> describeParameters(proxy, progress, proxyClient, progress.getResourceModel(), progress.getCallbackContext(), logger))
.then(progress -> listTagsForResourceRequestForParameters(proxy, progress, proxyClient, progress.getResourceModel(), progress.getCallbackContext(), logger))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to soft-fail wherever extra permissions are needed. (Like ListTags)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants