You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/APIGatewaySetupParameters.tt
+172-1Lines changed: 172 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -247,6 +247,177 @@
247
247
validationErrors.Add($"Value {__request__.Body} at 'body' failed to satisfy constraint: {e.Message}");
248
248
}
249
249
250
+
<#
251
+
}
252
+
}
253
+
else if (parameter.Attributes.Any(att => att.Type.FullName == TypeFullNames.FromCustomAuthorizerAttribute))
254
+
{
255
+
var fromAuthorizerAttribute = parameter.Attributes?.FirstOrDefault(att => att.Type.FullName == TypeFullNames.FromCustomAuthorizerAttribute) as AttributeModel<Amazon.Lambda.Annotations.APIGateway.FromCustomAuthorizerAttribute>;
256
+
257
+
// Use parameter name as key, if Name has not specified explicitly in the attribute definition.
258
+
var authKey = fromAuthorizerAttribute?.Data?.Name ?? parameter.Name;
259
+
// REST API and HTTP API v1 both use APIGatewayProxyRequest where RequestContext.Authorizer is a dictionary.
260
+
// Only HTTP API v2 uses APIGatewayHttpApiV2ProxyRequest with RequestContext.Authorizer.Lambda as the dictionary.
Copy file name to clipboardExpand all lines: Libraries/src/Amazon.Lambda.Annotations/README.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -894,6 +894,22 @@ parameter to the `LambdaFunction` must be the event object and the event source
894
894
* Map method parameter to HTTP request body. If parameter is a complex type then request body will be assumed to be JSON and deserialized into the type.
895
895
* FromServices
896
896
* Map method parameter to registered service in IServiceProvider
897
+
* FromCustomAuthorizer
898
+
* Map method parameter to a custom authorizer context value. Use the `Name` property to specify the key in the authorizer context if it differs from the parameter name. Returns HTTP 401 Unauthorized if the key is not found or type conversion fails.
899
+
900
+
Example using `FromCustomAuthorizer` to access values set by a custom Lambda authorizer:
context.Logger.LogLine($"User {userId} from tenant {tenantId}");
910
+
// userId and tenantId are automatically extracted from the custom authorizer context
911
+
}
912
+
```
897
913
898
914
### Customizing responses for API Gateway Lambda functions
899
915
@@ -940,4 +956,4 @@ The content type is determined using the following rules.
940
956
941
957
## Project References
942
958
943
-
If API Gateway event attributes, such as `RestAPI` or `HttpAPI`, are being used then a package reference to `Amazon.Lambda.APIGatewayEvents` must be added to the project, otherwise the project will not compile. We do not include it by default in order to keep the `Amazon.Lambda.Annotations` library lightweight.
959
+
If API Gateway event attributes, such as `RestAPI` or `HttpAPI`, are being used then a package reference to `Amazon.Lambda.APIGatewayEvents` must be added to the project, otherwise the project will not compile. We do not include it by default in order to keep the `Amazon.Lambda.Annotations` library lightweight.
0 commit comments