Include safe function code in infra bundle #10
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, infrastructure modules can safely import function modules (treating them as resources). This PR makes it possible for function modules to import infrastructure modules.
Why is this necessary? As discussed in discussion #2, there are use cases where a function will need to be configured based upon some infrastructure concerns. For example, a lambda that calls out to DynamoDB needs to have a policy that grants access to the table. The best place to define this is in the lambda, where the developer can see what access is actually required. Even better would be to put type constraints on the Dynamo DB client based on the access that has been granted e.g. can only call putItem if putItem access has been granted to the lambda role.
To achieve this, some code in the function module will need to be evaluated when generating the orchestration graph. To make this safe, we can eliminate everything from the module, except that which is definitely safe to evaluate.
The compiler does three things:
Because the heuristic is to opt-in safe code, and I have not covered every possible case, the resulting parser is quite aggressive. It will cull statements that are definitely safe. That's ok for now - the use cases will be limited.
This is a rough solution. It is not efficient, particularly as I didn't refactor the existing compiler transform, but it provides a reasonable foundation to build some interesting features.