Skip to content

ValueError: malformed url rule: '/my/images/<resource+>' #457

Closed

Description

@metaskills

Upgrading from v0.2 to v0.3 and I found my swagger 2.0 path expansion no longer works.

paths:
  "/my/images/{resource+}":

In version 2.0, this allowed me to expand that parameter to any path. So /my/images/foo/bar/img.png would yield a event.pathParameters.resource equal to foo/bar/img.png. This no longer works with this error being show.

ValueError: malformed url rule: '/my/images/<resource+>'

Activity

  1. metaskills commented on Jun 2, 2018

    @metaskills
    ContributorAuthor

    Here is an example template.yaml that work in both v0.2 locally and when deployed to AWS.

    AWSTemplateFormatVersion : '2010-09-09'
    Transform: AWS::Serverless-2016-10-31
    Description: The /my/images Lambda
    
    Resources:
      ImagesApi:
        Type: AWS::Serverless::Api
        Properties:
          StageName: development
          Variables:
            LambdaFunctionName: !Ref ImagesFunction
          DefinitionBody:
            swagger: "2.0"
            info:
              title: !Ref AWS::StackName
              basePath: /development
            schemes:
            - 'https'
            paths:
              "/my/images/{resource+}":
                get:
                  parameters:
                    - name: resource
                      in: path
                      required: true
                      type: string
                  x-amazon-apigateway-integration:
                    httpMethod: POST
                    type: aws_proxy
                    uri:
                      Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImagesFunction.Arn}:live/invocations
                  responses: {}
            x-amazon-apigateway-binary-media-types:
              - "*/*"
      ImagesFunction:
        Type: "AWS::Serverless::Function"
        Properties:
          Environment:
            Variables:
              STAGE: development
              MMS_BUCKET_NAME: mybucket
          FunctionName: 'my-images'
          Runtime: nodejs8.10
          Handler: index.default
          MemorySize: 512
          Timeout: 10
          CodeUri: "."
          Policies:
            - S3ReadPolicy:
                BucketName: mybucket
          Events:
            GetApi:
              Type: Api
              Properties:
                Path: /my/images/{resource+}
                Method: GET
                RestApiId: !Ref ImagesApi
  2. metaskills commented on Jun 2, 2018

    @metaskills
    ContributorAuthor

    Again, I have used this in AWS API Gateway with v0.2.x as others have noted (OAI/OpenAPI-Specification#892 (comment)) can we allow this project to do what staging/production env can do locally for dev? This blocks my upgrade to 0.3.x.

  3. metaskills commented on Jun 2, 2018

    @metaskills
    ContributorAuthor

    And I really wanted to upgrade to 0.3.0 for the binary data fixes to work locally.

  4. vasmik commented on Jun 6, 2018

    @vasmik

    I've faced with same issue
    for

    apiGet:
      Type: Api
        Properties:
            Path: /{version}/{service}/{path+}
            Method: GET
            RestApiId: !Ref ApiGateway
    

    I receive:

    Traceback (most recent call last):
      File "/Users/vasmik/Library/Python/2.7/bin/sam", line 11, in <module>
        sys.exit(cli())
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 722, in __call__
        return self.main(*args, **kwargs)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 697, in main
        rv = self.invoke(ctx)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 895, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/decorators.py", line 64, in new_func
        return ctx.invoke(f, obj, *args[1:], **kwargs)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/start_api/cli.py", line 56, in cli
        docker_network, log_file, skip_pull_image, profile)  # pragma: no cover
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/start_api/cli.py", line 86, in do_cli
        service.start()
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/lib/local_api_service.py", line 72, in start
        service.create()
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/samcli/local/apigw/service.py", line 81, in create
        methods=api_gateway_route.methods)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 64, in wrapper_func
        return f(self, *args, **kwargs)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1046, in add_url_rule
        self.url_map.add(rule)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/werkzeug/routing.py", line 1215, in add
        rule.bind(self)
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/werkzeug/routing.py", line 687, in bind
        self.compile()
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/werkzeug/routing.py", line 740, in compile
        _build_regex(self.is_leaf and self.rule or self.rule.rstrip('/'))
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/werkzeug/routing.py", line 715, in _build_regex
        for converter, arguments, variable in parse_rule(rule):
      File "/Users/vasmik/Library/Python/2.7/lib/python/site-packages/werkzeug/routing.py", line 210, in parse_rule
        raise ValueError('malformed url rule: %r' % rule)
    ValueError: malformed url rule: '/<version>/<service>/<path+>'
    
  5. added
    area/local/start-api
    on Jun 6, 2018
  6. sanathkr commented on Jun 6, 2018

    @sanathkr

    Turns out the code currently supports {proxy+} but not any other name instead of proxy. I have tagged it as a bug so we can fix. If you want a workaround, changing this the wildcard to word {proxy+} will solve.

    This code is implemented in one class here - https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/local/apigw/path_converter.py. It is a fairly self-contained change to a few regexes to fix this bug. If you are interested in contributing, I will be happy to guide you through.

  7. metaskills commented on Jun 7, 2018

    @metaskills
    ContributorAuthor

    I can confirm using {proxy+} as the name does provide a workaround. Thanks!

  8. jfuss commented on Jul 17, 2018

    @jfuss
    Contributor

    Arbitrary names for path expansions has been released with v0.5.0

    Closing as this is released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/local/start-apicontributors/good-first-issuepriority/1-criticaltype/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions