When deploying a serverless function with a wildcard parameter (e.g.: /accounts/{accountId}) with a custom authorizer, accessing context.resourcePath in the authorizer function when invoking the API with a value (/accounts/3), API Gateway context returns /accounts/{accountId}, whereas in serverless-offline, the value is populated with /accounts/3
Current Behavior
serverless-offline includes parameter values in context.resourcePath: /accounts/3
Expected behavior/code
serverless-offline uses the wildcard parameter, same as API Gateway context.resourcePath: /accounts/{accountId}
Unfortunately, no documentation is available in AWS docs, so the expected behaviour has to be tested on a live environment
Will work on it
@dherault We're experiencing the same behavior on a rather larger team. Is there a branch this is being worked on? I took a look at the active branches but didn't spot one.
I noticed this was added to the v6.1 milestone. Given this is a pretty big regression, is there any chance we can get a higher priority on it?
Plus one to this getting fixed!
We get the same issue.
Below the comparison of API Gateway event object and the one of serverless offline (v6.1.5):
API Gateway:
{
"resource": "/environments/{environmentId}/ip_restrictions/{ipRestrictionUuid}",
"path": "/environments/8/ip_restrictions/3901a526-bad9-48be-be84-2c362839c11f",
"requestContext": {
"resourcePath": "/environments/{environmentId}/ip_restrictions/{ipRestrictionUuid}",
"path": "/dev/environments/8/ip_restrictions/3901a526-bad9-48be-be84-2c362839c11f",
},
}
Serverless offline:
{
"resource": "/environments/8/ip_restrictions/3901a526-bad9-48be-be84-2c362839c11f",
"path": "/environments/8/ip_restrictions/3901a526-bad9-48be-be84-2c362839c11f",
"requestContext": {
"resourcePath": "/environments/8/ip_restrictions/3901a526-bad9-48be-be84-2c362839c11f",
"path": "/dev/environments/{environmentId}/ip_restrictions/{ipRestrictionUuid}",
},
}
We can see that requestContext.resourcePath is inverted with requestContext.path and resource is wrong.
I could look into implementing a fix in my first contribution to the project. @dherault are you actively working on it?
I accidentally closed this issue 馃う
Any chance we can get this change released?
With the version 6.3.1 I see:
API Gateway (authorizer and function):
{
"resource": "/v1/assessments/{assessmentId}/reports",
"path": "/v1/assessments/265674/reports",
"requestContext": {
"resourcePath": "/v1/assessments/{assessmentId}/reports",
"path": "/dev/v1/assessments/265674/reports"
}
}
Serverless Offline Authorizer:
{
"path": "/dev/v1/assessments/265674/reports",
"requestContext": {
"resourcePath": "/v1/assessments/265674/reports"
}
}
Serverless Offline Function:
{
"resource": "/v1/assessments/265674/reports",
"path": "/v1/assessments/265674/reports",
"requestContext": {
"resourcePath": "/dev/v1/assessments/{assessmentId}/reports",
"path": "/v1/assessments/265674/reports"
}
}
So in the API Gateway version we have:
. resource and requestContext.resourcePath: no /{stage} and no resolved vars
. path: no /{stage} and resolved vars
. requestContext.path: /{stage} and resolved vars
In Serverless Offline Authorizer:
. resource is not present (should be no /{stage} and no resolved vars)
. requestContext.resourcePath: no /{stage} and resolved vars (should not resolve vars)
. path: /{stage} and resolved vars (should not have /{stage})
. requestContext.path: is not present (should be /{stage} and resolved vars)
In Serverless Offline Function:
. resource: no /{stage} and resolved vars (should not resolve vars)
. requestContext.resourcePath: /{stage} and no resolved vars (should not have /{stage})
. path: no /{stage} and resolved vars (this is fine)
. requestContext.path: no /{stage} and resolved vars (should have /{stage})
v6.3.2
Thanks for the fix.
On thing, in v6.3.2 the variable resolution is correct in all cases but the /stage prefix is not.
In APIG the only property that has /stage is requestContext.path
In Serverless Offline Authorizer path has /stage and it shouldn't
In Serverless Offline Function resource and requestContext.resourcePath have /stage and it shouldn't and requestContext.path doesn't have /stage and it should
@danilofuchs Just want to point out that this has not been fixed, and the mixing up of the /stage prefix between path and resource is as problematic, if not more.
@chardos Can we reopen this issue, or would you prefer a new issue? Thanks
Most helpful comment
Thanks for the fix.
On thing, in v6.3.2 the variable resolution is correct in all cases but the /stage prefix is not.
In APIG the only property that has /stage is
requestContext.pathIn Serverless Offline Authorizer
pathhas /stage and it shouldn'tIn Serverless Offline Function
resourceandrequestContext.resourcePathhave /stage and it shouldn't andrequestContext.pathdoesn't have /stage and it should