apache / apisix-ingress-controller

APISIX Ingress Controller for Kubernetes
https://apisix.apache.org/
Apache License 2.0
1.02k stars 343 forks source link

request help: how to configure route without upstream (`aws-lambda` plugin) #2271

Open kayx23 opened 3 months ago

kayx23 commented 3 months ago

Issue description

An upstream is not required when using aws-lambda plugin. See:

With ingress controller, if you attempt to apply the following config:

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: aws-lambda-route
spec:
  http:
    - name: aws-lambda-route
      match:
        paths:
          - /something
      plugins:
      - name: aws-lambda
        enable: true
        config:
          function_uri: https://xxx.com
          authorization:
            iam:
              accesskey: xxx
              secretkey: xxx
              aws_region: us-east-2
              service: lambda
          timeout: 30000
          ssl_verify: false

You get the a schema check error:

The ApisixRoute "aws-lambda-route" is invalid: 
* <nil>: Invalid value: "": "spec.http[0]" must validate at least one schema (anyOf)
* spec.http[0].backends: Required value

What I have also attempted is to set an upstreams:

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: aws-lambda-route
spec:
  http:
    - name: aws-lambda-route
      match:
        paths:
          - /something
      upstreams:
      - name: https-upstream
      plugins:
      - name: aws-lambda
        enable: true
        config:
          function_uri: https://xxx.com
          authorization:
            iam:
              accesskey: xxx
              secretkey: xxx
              aws_region: us-east-2
              service: lambda
          timeout: 30000
          ssl_verify: false
---
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: https-upstream
spec:
  scheme: https
  loadbalancer:
    type: roundrobin

With this you do get around the schema check but you would see an empty ExternalNodes or Discovery configuration error in the ingress controller log:

2024-08-01T17:39:26+08:00   error   translation/apisix_route.go:243 failed to translate ApisixUpstream at Upstream[0]   {"error": "default/https-upstream has empty ExternalNodes or Discovery configuration", "apisix_upstream": "default/amazon-bedrock-upstream"}

So what should be the right way to configure aws-lambda on a route that does not require an upstream? Or is this scenario something ingress controller schema should accommodate for?

Note: aws-lambda plugin does not have test coverage in this repo as of now.

Environment

Revolyssup commented 3 months ago

https://github.com/apache/apisix-ingress-controller/blob/bbcd8d9e24ea40e168df416bd69cd0f4f9603cc5/test/e2e/suite-features/external-service.go#L258 Refer to this test case

Revolyssup commented 3 months ago

I see this plugin terminates the original request. So doesn't matter what the upstream is. Creating ApisixRoute creates an upstream automatically so it still requires backend field to be configured. As a workaroud, you can configure an externalservice as the same URL and use that as backend. Though that upstream won't be used. But currently ingress controller doesn't support creating ApisixRoute with upstream.

kayx23 commented 3 months ago

As a workaroud, you can configure an externalservice as the same URL and use that as backend.

Adopting this workaround for now and keeping this issue to track future actions (if any).

github-actions[bot] commented 1 week ago

This issue has been marked as stale due to 90 days of inactivity. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.