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

feat(invoke): reading Metadata adding to Resources in a template #907

Merged
merged 5 commits into from
Jan 11, 2019

Conversation

jfuss
Copy link
Contributor

@jfuss jfuss commented Jan 3, 2019

💻 Rendered Design Doc is here
🗓 RFC Open for feedback until: 1/10/2018

Description of changes:

This design is meant to capture how we can directly support templates that are embedded with Metadata CDK appended into the template. This will allow customers to synthesize templates written in CDK and locally debug/invoke their functions through SAM CLI. While understanding CDK Metadata is the only thing in scope for this design, it is left open to allow further support and expansion (most likely through another command) that can generate the AWS CloudFormation templates directly within SAM CLI.

Checklist:

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

@jfuss jfuss requested a review from sriram-mv January 3, 2019 21:56
@jfuss
Copy link
Contributor Author

jfuss commented Jan 3, 2019

As an FYI: @sooddhruv @eladb @fulghum


```python

class CdkTemplateNormalizer(object):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about this more. I think this should be a metadata normalized instead of tying it to CDK. CDK happens to be the first to add this type of metadata but nothing here forces it to be from CDK.

I will work on removing references to that directly and center the design around the Metadata instead. I will also add a snippet of the Metadata on a Resource (slipped my mind when initially writing)

Copy link

Choose a reason for hiding this comment

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

+1 we designed the metadata keys (aws:asset:*) to not be tied directly to cdk with the purpose of allowing other frameworks to utilize the same approach.

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

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

This looks to be a good step in the process. I just had a few questions.

Below algorithm to do this Metadata Normalization on the template.

```python
class TemplateMetadataNormalizer(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this normalizer going to be injected? can we have more than one normalizer such that we can chain them?

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 will not be injected. The Method is static. I wanted to keep this out of the SamBaseProvider class, so it can make the decision on when/where to run this in the flow of getting the template_dict. It is possible to have more than one normalizer but they could happen at different times. For now, I elected to keep it simple and just make the method call to this class where we needed.

```

The two keys we will recognize are `aws:asset:path` and `aws:asset:property`. `aws:asset:path`'s value will be the path
to the code, files, etc that are help on the machine, while `aws:asset:property` is the Property of the Resource that
Copy link

Choose a reason for hiding this comment

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

״help on the machine״?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how 'help' got into that sentence.

@jfuss jfuss changed the title feat(cdk): Design for reading CDK Metadata embedded in a template feat(invoke): reading Metadata adding to Resources in a template Jan 7, 2019
}
}

ResourceMetadataNormalizer.normalize(template_data)
Copy link

Choose a reason for hiding this comment

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

Shouldn’t that be an error? Or at least a warning ⚠️?

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 is done on the full template, which means a resource not being invoked could fail the invoke of another and don't think that is the correct UX. Maybe there are cases like start-api or start-lambda that could require this to be a failure but the CLI doesn't have any distinctions about which command is run.

A warning seems reasonable.

if property_key and property_value:
resource.get(PROPERTIES_KEY, {})[property_key] = property_value
elif property_key or property_value:
LOG.info("WARNING: Ignoring Metadata for Resource %s. Metadata contains only aws:asset:path or "
Copy link

Choose a reason for hiding this comment

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

LOG.warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will not get logged to console by default (due to how we currently have logging setup) and the pattern we have followed thus far is using LOG.info instead. There is a bigger story here on our logging (including adding colors to make reading easier) but that is for another day.

Copy link

Choose a reason for hiding this comment

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

Sure no prob

@sriram-mv
Copy link
Contributor

I dont see any major concerns, looks good to me. 👍

@sriram-mv sriram-mv self-assigned this Jan 9, 2019
@jfuss jfuss merged commit 29e2250 into aws:develop Jan 11, 2019
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