-
Notifications
You must be signed in to change notification settings - Fork 2.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
RFC: Allow customizations on AWS::Serverless::Function API event types #931
Comments
@beck3905 I like this idea. Like you posted, there are several features in https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html that could be useful in API Events. Some of these issues are:
Could you provide any sample syntax of how you might like to use some of these features? Or any other features that you think would be good to add to the API Event? |
@keetonian I recently had a use case where I had an API with caching enabled that requires an Authorization token. Because the caching only looks at the URL and not the headers the cache would return valid values for users with invalid tokens and would return data for other users. Obviously, this was a problem. I solved it by adding the Authorization header parameter to the Method Request and enabling caching on that parameter. Since Serverless::API is pretty much all or nothing with swagger, the only way to accomplish this was with swagger. However, if the https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-requestparameters were available in the API event then I would've only had to add a small bit of configuration there to accomplish the same thing. I suggest exposing the following properties in the API event source type:
For example:
|
@keetonian I've submitted a PR for my first stab at this. I implemented the RequestModel support in #948. Would you please take a look? |
@keetonian I've just submitted a second PR for RequestParameters support in #953. Would you please also take a look at that? |
@keetonian is there an estimate date on when will this be released ? |
@MohammedAlSafwan We're working on making our release process more transparent to external customers, but we're not quite where we want to be yet. For now, you can see when we cut release branches, which can give you some indication of when we begin working on a specific release. |
@beck3905 While writing tests for this feature during our internal QA process for Release V1.15, here's what i discovered -
Globals:
Api:
OpenApiVersion: '3.0.1'
CacheClusterEnabled: true
CacheClusterSize: '0.5'
MethodSettings:
- ResourcePath: /one
HttpMethod: "GET"
CachingEnabled: true # required to enable caching
CacheTtlInSeconds: 15 # optional
Resources:
ApiParameterFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = function(event, context, callback) {
var returnVal = "undef";
if (event.queryStringParameters.type === "time") {
returnVal = "time " + Date.now();
}
if (event.queryStringParameters.type === "random") {
returnVal = "Random " + Math.random();
}
callback(null, {
"statusCode": 200,
"body": returnVal
});
}
Handler: index.handler
Runtime: nodejs8.10
Events:
GetHtml:
Type: Api
Properties:
Path: /one
Method: get
RequestParameters:
- method.request.querystring.type:
Required: true
Caching: true
AnotherGetHtml:
Type: Api
Properties:
Path: /two
Method: get |
|
Thanks for getting back @beck3905
|
@praneetap I agree. Does this mean that this feature is not releasable until those 2 things are accomplished? Or can this be released and then address the 2 things in a future release? Thanks. Side-note: Will any of you be at RE:Invent this year? I would love to put faces to names as you all have been so much help in moving these issues and PRs forward and I hope to continue contributing to SAM. |
We decided to move forward with releasing this anyway because it adds a lot of value as is. Updating it to add
That just made my day! :) thank you. I won't be going unfortunately, but I am sure someone from my team will be there. More a question for @jlhood I think. We really look forward to meeting SAM contributors :) |
@beck3905 Yes, I'll be at re:Invent this year giving some talks and working at the serverless booth at the expo. Would love to meet up with you as well! Twitter is probably the best way to reach out to me (@jlhcoder). Message me as the date gets closer, and we'll try to find a time that works. 😊 |
Closing this issue as v1.15.0 is released |
@ShreyaGangishetty I think there is more work to be done related to this issue. Only part of it was released in v1.15.0. Should this issue remain open to account for that remaining work? |
Adding
And in API GW console, under URL Query String Parameters, it shows this warning:
This makes us to need to updated RequestParameters in template (in order to have updated Swagger specs) and to update Lambda business logic (to perform validation). So it's extra work and can lead to inconsistency. |
@praneetap mentioned this in #931 (comment) This is an open feature request to add validators. |
I tried to add caching to a method with a parameter My setup is as follows:
The GET method at the Prod stage is marked as
|
I think I just found my own mistake.
It's sad I don't get an error though. |
@tuler agree, it looks like SAM should add an error at that point for an incorrect configuration. It looks like SAM reads it as a list, some digging is needed to see why an error wasn't thrown when you gave it a dictionary. |
This works also for querystring, however, I cant find anything in the documentation about setting Request Validator. |
It looks like piecewise specification of endpoint method parameters in the stack template is not going to be sufficient to cover the entire API schema. An OpenAPI specification document is going to be a better approach. See: aws/serverless-application-model#931
Looks like part of this is done but it's unclear if all of it is done. Given part is done and how old this is, I am going to close it. If there is parts of the initial request are still valuable, please open a discussion for the feature request. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Swagger seems to be an all-or-nothing approach to AWS::Serverless::Api resources. If the swagger definition is provided in the API then the entire API needs to defined in swagger. I often have a single AWS::Serverless::Function that needs some customization in how it should be defined in the API, but in order to accomplish that I would need to provide boilderplate swagger for the entire API plus my customization.
It would be much more convenient and simple if I could just add my customizations to the Lambda API event and the translator would apply these to the API definition for that specific function.
The text was updated successfully, but these errors were encountered: