amazon-web-services - AWS API 网关 - 私有(private)端点 - 消息被禁止

标签 amazon-web-services curl aws-api-gateway amazon-vpc

我正在尝试设置私有(private) AWS API 网关并从我的笔记本电脑连接到它。膝上型电脑驻留在 AWS Direct Connect'ed 到私有(private) VPC 的网络中。为此,我正在使用 AWS 提供的玩具示例“PetStore”API。

根据 this guide :

  • 为我的 VPC 建立了 API 网关服务端点(禁用私有(private) DNS)
  • 给它一个安全组,允许来自 本地网络(我的笔记本电脑所在的网络)
  • 将 API 网关创建为私有(private) API
  • 更新了资源政策
  • 将 API 部署为阶段 V1

假设:

  • AWS账号:123456789012
  • AWS 区域:eu-central-1
  • API 网关 ID:abcdefghij
  • API 阶段:V1
  • VPC 端点域:vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com
  • VPC端点IP:10.10.10.10

为了调用我的 API,我调用了以下 cURL 命令:

curl -v https://vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com/V1/pets -H 'Host: abcdefghij.execute-api.eu-central-1.amazonaws.com' --noproxy "*"

这是结果:

*   Trying 10.10.10.10...
* TCP_NODELAY set
* Connected to vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com (10.54.251.244) port 443 (#0)
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 240 bytes...
* schannel: sent initial handshake data: sent 240 bytes
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 2/3)
* schannel: encrypted data got 4096
* schannel: encrypted data buffer: offset 4096 length 4096
* schannel: encrypted data length: 4000
* schannel: encrypted data buffer: offset 4000 length 4096
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 2/3)
* schannel: encrypted data got 1024
* schannel: encrypted data buffer: offset 5024 length 5024
* schannel: encrypted data length: 95
* schannel: encrypted data buffer: offset 95 length 5024
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 2/3)
* schannel: encrypted data got 252
* schannel: encrypted data buffer: offset 347 length 5024
* schannel: sending next handshake data: sending 126 bytes...
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 2/3)
* schannel: encrypted data got 51
* schannel: encrypted data buffer: offset 51 length 5024
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com port 443 (step 3/3)
* schannel: stored credential handle in session cache
> GET /V1/pets HTTP/1.1
> Host: vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com
> User-Agent: curl/7.55.1
> Accept: */*
>
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 364
* schannel: encrypted data buffer: offset 364 length 103424
* schannel: decrypted data length: 283
* schannel: decrypted data added: 283
* schannel: decrypted data cached: offset 283 length 102400
* schannel: encrypted data length: 52
* schannel: encrypted data cached: offset 52 length 103424
* schannel: decrypted data length: 23
* schannel: decrypted data added: 23
* schannel: decrypted data cached: offset 306 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 306 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 306
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 403 Forbidden
< Server: Server
< Date: Fri, 25 Oct 2019 11:32:01 GMT
< Content-Type: application/json
< Content-Length: 23
< Connection: keep-alive
< x-amzn-RequestId: a5aa9f76-4e3b-4315-838a-e859fa192ade
< x-amzn-ErrorType: ForbiddenException
< x-amz-apigw-id: jdsak!291kd
<
{"message":"Forbidden"}* Connection #0 to host vpce-1234567890.execute-api.eu-central-1.vpce.amazonaws.com left intact
* Rebuilt URL to: abcdefghij.execute-api.eu-central-1.amazonaws.com'/
* Could not resolve host: abcdefghij.execute-api.eu-central-1.amazonaws.com'
* Closing connection 1
curl: (6) Could not resolve host: abcdefghij.execute-api.eu-central-1.amazonaws.com'

有这个 {"message":"Forbidden"} 我不确定它来自哪里。还有错误 Could not resolve host: abcdefghij.execute-api.eu-central-1.amazonaws.com

所以我的问题是:这个问题从何而来?

附录

资源政策

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:eu-central-1:123456789012:abcdefghij/*"
        }
    ]
}

最佳答案

我遇到过与资源政策相关的类似问题。尝试使用以下策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:${AWS_REGION}:${AWS_ACCOUNT_ID}:${API_GETWAY_ID}/*/*/*",
            "Condition": {
                "StringNotEquals": {
                    "aws:sourceVpc": "${VPC_ENDPOINT_ID}"
                }
            }
        }
    ]
}

另外,确保 VPC 端点 ID 包含您的 vpce:

enter image description here

关于amazon-web-services - AWS API 网关 - 私有(private)端点 - 消息被禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58570286/

相关文章:

java - AWS 简单电子邮件服务 - Java 接收 Lambda 和 STOP_RULE

amazon-web-services - S3 MFA 删除是否会阻止存储桶本身被删除?

java - 使用 cURL 发布 JSON 正文的 Ant exec 任务不起作用,相同的命令在 Windows 命令提示符下手动工作

amazon-web-services - 映射模板的默认内容类型

aws-api-gateway - API Gateway 集成响应模型模板 - 删除属性

ruby-on-rails - AWS ELB 在重定向时继续在 Location header 中显示私有(private) IP

javascript - x-amzn-错误类型 :UnrecognizedClientException While Calling AWS Api gateway with temporary Credentials

php - 将子网的特定 IPv6 地址分配给 cURL

windows - WINDOWS RESTful 服务上的 cURL POST 命令行

amazon-web-services - 如何将 URL 部分映射到 AWS API 网关中的参数?