Skip to content

Conversation

rjlohan
Copy link
Contributor

@rjlohan rjlohan commented Nov 16, 2018

Initial Lambda Wrapper Implementation

This commit includes a basic framework for a Java Lambda wrapper for RPDK handlers.
It includes some temporary files and types which need to be refactored out in favour
of the actual RPDK handler implementations.

No tests exist yet, given the expected refactoring which will happen.

This PR also drops an initial implementation for #2

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rjlohan rjlohan added the enhancement New feature or request label Nov 16, 2018
tobywf
tobywf previously requested changes Nov 16, 2018
Copy link
Contributor

@tobywf tobywf left a comment

Choose a reason for hiding this comment

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

some initial feedback, mainly about dates

@rjlohan rjlohan force-pushed the initial-lambda-wrapper-2 branch 2 times, most recently from 433368c to 6432429 Compare November 16, 2018 23:09
Action action,
RequestContext context) {

Gson gson = new GsonBuilder().create();
Copy link
Contributor

Choose a reason for hiding this comment

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

just wondering, what was the reasoning for picking Gson over Jackson?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No specific reason. But it works.

request.getAction(),
(endTime.getTime() - startTime.getTime()));

// When the handler responses InProgress with a callback delay, we trigger a callback to re-invoke
Copy link
Contributor

Choose a reason for hiding this comment

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

if the handler wants to record additional progress events, how would it do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBD in future PR.

return null;
}

public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
Copy link
Contributor

@aygold92 aygold92 Nov 16, 2018

Choose a reason for hiding this comment

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

where is the POJO which contains the ResourceRequest we get from CloudFormation?
I don't see clientRequestToken or credentials anywhere.

Also, resourceTypeVersion, nextToken for List calls, previousResourceProperties, behaviorSpec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs iteration and refactoring to consume the actual handler interface and context object. So far, just a Lambda wrapper for a basic function.


public void publishInvocationMetric(final Date timestamp, final Action action) {
publishMetric(
Metrics.METRIC_NAME_HANDLER_INVOCATION_COUNT,
Copy link
Contributor

@aygold92 aygold92 Nov 16, 2018

Choose a reason for hiding this comment

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

how is this meant to work? invocations by the handler or by cloudwatch? if both, how would we keep track?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This metric is indicating the handler is running. CloudFormation will perform the initial invocation, but since the wrapper re-invokes itself, there may be many more actual invokes are CFN hands off.

* If the request was the result of a CloudWatchEvents re-invoke trigger the
* CloudWatchEvents Trigger Id is stored to allow cleanup
*/
private String cloudWatchEventsTargetId;
Copy link
Contributor

@aygold92 aygold92 Nov 16, 2018

Choose a reason for hiding this comment

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

why would the handler implementation care about the cloudWatch stuff or the invocation count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This RequestContext object comes unto Lambda, it's not passed to the Handlers.

Copy link
Contributor

Choose a reason for hiding this comment

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

This commit includes a basic framework for a Java Lambda wrapper for RPDK handlers.
It includes some temporary files and types which need to be refactored out in favour
of the actual RPDK handler implementations.

No tests exist yet, given the expected refactoring which will happen.
@rjlohan rjlohan force-pushed the initial-lambda-wrapper-2 branch from 6432429 to a83bb79 Compare November 16, 2018 23:15
Copy link
Contributor

@aygold92 aygold92 left a comment

Choose a reason for hiding this comment

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

looks fine for initial PR, other than the try/catch


final Gson gson = new GsonBuilder().create();
final JsonObject jsonObject = gson.toJsonTree(request.getResourceModel()).getAsJsonObject();
final ResourceModel model = gson.fromJson(jsonObject.toString(), ResourceModel.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

was going to ask if we can do this stuff for them; it looks like you half way did it when you declared the argument as HandlerRequest<ResourceModel>

public void handleRequest(final InputStream inputStream,
final OutputStream outputStream,
final Context context) throws IOException {
this.logger = context.getLogger();
Copy link
Contributor

@aygold92 aygold92 Nov 19, 2018

Choose a reason for hiding this comment

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

this whole function should be surrounded in try/catch/finally and return some response to CloudFormation to know when it fails (like with an NPE or some other bug of ours), and record metrics (I'd say metrics stuff can be done in a later PR, but I think the try/catch and write response should be in this one)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've raised #8 to do this later, once the interface back to the caller is cleaned up a bit.

@rjlohan rjlohan merged commit 7f465b4 into master Nov 19, 2018
@tobywf tobywf deleted the initial-lambda-wrapper-2 branch November 27, 2018 22:13
brianlaoaws added a commit to brianlaoaws/cloudformation-cli-java-plugin that referenced this pull request Nov 25, 2024
…brianlao-github-fort

Fix resource targetting for a stack level hook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants