admin管理员组

文章数量:1122832

So I'm currently developing a Google Chrome extension in Node.js. As part of the extension, I'm making calls to the OpenAI API, and I'm building a backend for these calls to be done securely on AWS Lambda. I'm using Terraform to build the Lambda configuration, which uses an AWS API Gateway. This is the TF CORS configuration for the API gateway:

resource "aws_apigatewayv2_api" "http_api" {
    name          = "ExpressAPI"
    protocol_type = "HTTP"

    cors_configuration {
        // Extension ID comes from mimic extension on Chrome
      allow_origins = ["chrome-extension://<chrome-extension-id>"]
      allow_methods = ["OPTIONS", "POST"]
      allow_headers = ["Content-Type", "Authorization"]
    }
}

When I include this in the TF configuration and run "terraform apply", I get the following error:

│ Error: updating API Gateway v2 API (<aws-account-id>): operation error ApiGatewayV2: UpdateApi, https response error StatusCode: 400, RequestID: <request-id>, BadRequestException: Invalid format for origin chrome-extension://<chrome-extension-id>
│
│   with aws_apigatewayv2_api.http_api,
│   on lambda.tf line 18, in resource "aws_apigatewayv2_api" "http_api":
│   18: resource "aws_apigatewayv2_api" "http_api" {

I get the same error when I try to include the extension url (chrome-extension://) in the AWS console, obviously including the actual chrome extension id where the placeholder is. So my question is, how do you get a Google Chrome extension to access an AWS Lambda function via an Express API and its endpoints? Since AWS doesn't seem to allow a chrome-extension origin.

I've read that this can be done with an HTTPS proxy server with something like NGINX in order to handle the CORS layer and to allow the chrome-extension:// origin. Is this the best way to do it, or is there a more simple way to go about this. Any insight would be appreaciated, thanks!

本文标签: