-
Notifications
You must be signed in to change notification settings - Fork 4k
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(assets): enable local tooling scenarios such as lambda debugging #1433
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0d2d6a
doc: RFC for code asset metadata
9eeb8de
Close backticks
ad1a902
feat(assets): enable local tooling scenarios such as lambda debugging
a081639
revert unwanted change in function
416b6ba
Support disabling asset metadata (and disable in integ tests)
0f83270
Fix test
1ce906f
Update design doc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# RFC: AWS Lambda - Metadata about Code Assets | ||
|
||
As described in [#1432](https://github.com/awslabs/aws-cdk/issues/1432), in order to support local debugging, | ||
debuggers like [SAM CLI](https://github.com/awslabs/aws-sam-cli) need to be able to find the code of a Lambda | ||
function locally. | ||
|
||
The current implementation of assets uses CloudFormation Parameters which represent the S3 bucket and key of the | ||
uploaded asset, which makes it impossible for local tools to reason about (without traversing the cx protocol with | ||
many heuristics). | ||
|
||
## Approach | ||
|
||
We will automatically embed CloudFormation metadata on `AWS::Lambda::Function` resources which use | ||
local assets for code. The metadata will allow tools like SAM CLI to find the code locally for local invocations. | ||
|
||
## Design | ||
|
||
Given a CDK app with an AWS Lambda function defined like so: | ||
|
||
```ts | ||
new lambda.Function(this, 'MyHandler', { | ||
// ... | ||
code: lambda.Code.asset('/path/to/handler') | ||
}); | ||
``` | ||
|
||
The synthesized `AWS::Lambda::Function` resource will include a "Metadata" entry as follows: | ||
|
||
```js | ||
{ | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
// current asset magic | ||
} | ||
}, | ||
"Metadata": { | ||
"aws:asset:property": "Code", | ||
"aws:asset:path": "/path/to/handler" | ||
} | ||
} | ||
``` | ||
|
||
Local debugging tools like SAM CLI will be able to traverse the template and look up the `aws:asset` metadata | ||
entries, and use them to process the template so it will be compatible with their inputs. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only
AWS::Lambda::Function
s? What aboutAWS::Lambda::LayerVersion
,AWS::Serverless::Function
, andAWS::Serverless::LayerVersion
?We are purposefully excluding API Gateway from this correct?
Is there a generic way this could work to allow any resource using an Asset to get this metadata? Trying to think broader here to make less work in the future of manually adding this metadata to every resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation allows anyone who uses an asset to attach this metadata to the resource by calling
asset.addResourceMetadata(resource, prop)
. I decided against doing this automatically because this problem is basically confined to only L2 constructs. Any higher level constructs shouldn't care about this at all, so I opted for a more manual solution.Layers are currently in PR (#1411) and @RomainMuller should probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eladb What about
AWS::Serverless::Function
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfuss the
AWS::Serverless::Function
is currently only supported as an L1 construct (serverless.CfnFunction
), and I suspect people who use it will likely not try to use it with CDK assets but rather withCodeUri
. For example:If users wish to use CDK assets (and invoke them locally through SAM CLI), this is what they will have to do:
But TBH, I doubt that this makes sense. If you are already writing "CDK native" code, the L2 constructs for Lambda, API Gateway, etc provides a much richer API then the
AWS::Serverless::Function
resource.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eladb I see. So it's more like
Assets
aren't directly supported withinAWS::Serverless::Function
like it is withAWS::Lambda::Function
s (over simplifying here due to the Construct level difference). I see Assets being powerful and something we should consider supporting directly but out of scope for this PR.Thanks for clarifying this.