question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

aws_apigatewayv2: add authorizer to route with HttpApi

See original GitHub issue

The Question

How do I add an authorizer to a route in my HttpApi (with cdk using python)?

http_api = _apigw2.HttpApi(self, "ApiGwId",
                                   api_name="HttpGateway",
                                   cors_preflight=cors_preflight,
                                   )

authorizer = _apigw2.CfnAuthorizer(self, "MyAuthorizer",
                              api_id=http_api.http_api_id,
                              authorizer_type="JWT",
                              jwt_configuration={
                                  "audience": [user_pool_client.user_pool_client_id], "issuer": "myissuer"},
                              identity_source=[
                                  '$request.header.Authorization'],
                              name="Myauthorizer",
                              )

http_api.add_routes(
            path='/example',
            methods=[_apigw2.HttpMethod.GET],
            integration=my_lambda_integration,
        )

–>

Environment

  • CDK CLI Version: 1.45.0
  • Module Version: 1.45.0
  • Node.js Version: v14.0.0
  • OS: WSL2 in Windows 10
  • Language (Version): Python (3.7.3)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
stilrencommented, Jul 22, 2020
2reactions
stilrencommented, Jun 22, 2020

Figured it out:

    for route in routes:
        routeCfn = route.node.default_child
        routeCfn.authorizer_id=authorizer.ref
        routeCfn.authorization_type = 'JWT'
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-apigatewayv2-authorizers module
You can set an authorizer to your WebSocket API's $connect route to control access to your API. Lambda Authorizer. Lambda authorizers use a...
Read more >
[@aws-cdk/aws-apigatewayv2] support authorizers for HTTP API
I want to be able to add an authorizer when calling the addRoutes method. Similar to what is done in the apigateway construct: ......
Read more >
@aws-cdk/aws-apigatewayv2-authorizers-alpha - npm
Access control for Http Apis is managed by restricting which routes can be invoked via. Authorizers and scopes can either be applied to...
Read more >
HTTP API Gateway - How to map authorizer to route in ...
As it's currently written, it's hard to tell exactly what you're asking. – Community Bot. Sep 20 at 11:15. Add a comment ...
Read more >
terraform-aws-modules/apigateway-v2/aws | Terraform Registry
Terraform module to create an AWS API Gateway v2 (HTTP/WebSocket) ... timeout_milliseconds = 12000 } "GET /some-route-with-authorizer" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found