Các phương thức xác thực Cổng API AWS

Cho đến nay, chúng tôi đã đề cập khá nhiều về cách ứng dụng của chúng tôi được kiến ​​trúc. Nếu bạn bỏ lỡ việc theo dõi nó, hãy xem bài đăng blog khác của chúng tôi trong loạt bài này

  • Sử dụng AWS Managed Services trong môi trường doanh nghiệp
  • Thiết kế các API theo mô-đun, có thể triển khai và bảo mật
  • AWS Cognito + AWS Lambda + Serverless Framework + Phản ứng với Redux
  • Nghiên cứu điển hình trong thiết kế mô-đun

Bạn có nhiều tùy chọn khác nhau khi triển khai ủy quyền và xác thực. Chúng tôi không có yêu cầu cụ thể nào ngoài việc cần phải có một số thứ và nó không thể là “tĩnh” [e. g. tên người dùng và mật khẩu được mã hóa cứng được chuyển cùng với yêu cầu mọi thứ]

Chúng tôi đã xem xét các tùy chọn khác nhau trước khi giải quyết trên Cổng API. Là một ứng dụng NodeJS, Passport là lựa chọn phổ biến nhất. Tôi cũng đã xây dựng phương thức xác thực của riêng mình cho một dự án khác [ghi chú bên lề. không bao giờ làm điều này]. Tuy nhiên, cuối cùng, chúng tôi muốn một cái gì đó mà chúng tôi không phải duy trì sức khỏe của

Cổng API để giải cứu

Cổng API dường như hoàn toàn phù hợp ngoại trừ một điều. vào thời điểm đó, bạn không thể đặt Cổng API trước các tài nguyên bên trong VPC

Sau một số cuộc thảo luận, chúng tôi quyết định đánh cược. Ứng dụng của chúng tôi chỉ chạy trong môi trường phòng thí nghiệm và sẽ mất một thời gian trước khi nó được đưa ra internet công cộng. Đồng thời, chúng tôi đã quyết định rằng bất cứ điều gì chúng tôi sử dụng để ủy quyền và xác thực, nó sẽ phải được triển khai theo cách tương tự như API Gateway; . Chức năng này sẽ không được nhúng trong mã ứng dụng của chúng tôi. Nếu chúng tôi chọn thứ gì đó hoạt động theo cách tương tự, thì việc chuyển đổi sẽ dễ dàng hơn nếu API Gateway trở nên khả thi

Vì vậy, chúng tôi đã chờ đợi và nghiên cứu các lựa chọn khác. Chúng tôi không biết liệu AWS có bao giờ hỗ trợ kịch bản như vậy không. Tất cả những gì chúng tôi có thể tìm thấy là một số bài đăng diễn đàn ngẫu nhiên từ diễn đàn chính thức nói rằng họ đang xem xét nó

Ý tôi là… NLB để giải cứu

Vào cuối năm 2017, chúng tôi đã có một chiếc phao cứu sinh. AWS đã phát hành Bộ cân bằng tải mạng của họ, cuối cùng đã cho chúng tôi khả năng hiển thị tài nguyên bên trong VPC của chúng tôi thông qua Cổng API

Tôi không muốn sử dụng NLB Quá tệ. Tại thời điểm viết bài này, nếu bạn muốn sử dụng API Gateway và VPC, nó phải nằm sau NLB

Làm thế nào để làm điều này xảy ra

Chúng tôi sẽ tạo các mẫu hình thành đám mây cho phần sau…

1. Cân bằng tải mạng
2. Mục tiêu của Cân bằng tải mạng
3. Cổng API
4. Triển khai cổng API

Tôi không thể sử dụng bảng điều khiển? . Chúng tôi triển khai ứng dụng của mình bằng CFT. Không có lợi gì khi làm điều này thông qua bảng điều khiển trừ khi bạn có ý định định cấu hình thủ công tất cả các tài nguyên của mình, trên tất cả các môi trường của bạn. Nhưng đừng làm thế. Sử dụng CFT sẽ giúp triển khai ứng dụng của bạn dễ dàng hơn nhiều

Cân bằng tải mạng và các mục tiêu của nó

CFT cho bộ cân bằng tải khá dễ hiểu. Nó trông như thế này

Description: Load Balancer for ApplicationAPI
Parameters:
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Subnets:
Type: List
Description: List of Subnets, need to be across 2 availability zones
Resources:
ApplicationAPILoadBalancer:
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-lb'
Scheme: internal
Subnets: !Ref Subnets
Type: network
IpAddressType: ipv4

Chỉ cần một tên

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
9, có thể là bất cứ thứ gì có ý nghĩa với bạn. Cũng được cung cấp là danh sách các mạng con mà bạn muốn dịch vụ ECS của mình chạy trong đó

Giải thích về Tên giai đoạn Giai đoạn là một biến chúng tôi sử dụng trên tất cả các CFT của mình, vì vậy bạn sẽ thấy nó rất nhiều. Chúng tôi sử dụng nó để phân biệt giữa những gì được gọi là “môi trường” theo truyền thống. Vì vậy, chúng tôi có giai đoạn “dev”, giai đoạn “staging” và những giai đoạn khác nếu cần

Tiếp theo chúng ta cần thiết lập các mục tiêu. CFT trông giống như thế này

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP

Thuộc tính

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
0 rất quan trọng để làm việc này với Fargate. Nhóm mục tiêu của NLB cần biết rằng nó đang cân bằng giữa các Địa chỉ IP, thay vì id cá thể. Mục tiêu sẽ được liên kết với dịch vụ ECS trong một CFT khác và chính từ kết nối đó, Fargate sẽ có thể liên kết Địa chỉ IP với các nhóm mục tiêu của bộ cân bằng

Lưu ý rằng cũng có một

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
1, tạo trình nghe cho NLB của chúng tôi, kiểm tra các yêu cầu kết nối và chuyển tiếp chúng đến các nhóm mục tiêu

Cổng API

Cổng API này nằm trước một ứng dụng đang chạy trong Fargate. Ứng dụng đó có các tuyến được hiển thị và trả về mã trạng thái HTTP hợp lệ tùy thuộc vào tình huống. Với điều đó, Cổng API có thể đơn giản cho phép các yêu cầu và phản hồi chuyển qua lại

Ghi chú nhanh về ứng dụng của chúng tôi Đó là ứng dụng NodeJS sử dụng Koa làm máy chủ web. Nó có các tuyến được xác định bằng mô-đun koa-router và nghiêm ngặt về việc đảm bảo rằng tất cả đầu ra đều thân thiện với HTTP. Điều này cho phép API Gateway hoạt động như một proxy đơn giản. Chúng tôi có thể giao một số trách nhiệm đó cho API Gateway, nhưng điều đó không hợp lý do một số yêu cầu ứng dụng khác của chúng tôi

Có thể xác định một loạt

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
2 trong CFT cho Cổng API của bạn để xác định tuyến đường, nhưng có một số điều bạn không thể tận dụng nếu đi theo cách đó, chẳng hạn như đặt Liên kết VPC

Vì vậy, bạn sẽ cần xác định một

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
0 với một
Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
1 chứa định nghĩa cho các tuyến đường của bạn. Cách dễ nhất để khởi động CFT này là xây dựng Cổng API theo cách thủ công trong bảng điều khiển, triển khai nó và sau đó sử dụng tùy chọn xuất. Để làm điều đó, hãy chọn Giai đoạn > [tên sân khấu] > Xuất > Xuất dưới dạng Swagger + Tiện ích mở rộng cổng API. Sao chép/Dán đầu ra dưới dạng
Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
1 cho
Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
0 của bạn và bạn sẽ tiếp tục

Đợi đã, tại sao tôi lại xây dựng cái này trong bảng điều khiển trước? . CORS là ví dụ hoàn hảo. Đó là một nút duy nhất trong bảng điều khiển, nhưng không có cờ

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
4 trong hệ thống đám mây. Bạn phải thêm các định nghĩa tiêu đề cụ thể mà bạn sẽ thấy bên dưới. Chúng tôi chỉ đơn giản là thấy dễ dàng hơn khi bắt đầu với bảng điều khiển trước

Bước cuối cùng, hãy xóa Cổng API bạn vừa tạo. Bạn sẽ triển khai nó bằng CFT vào lần tới

Sau khi khởi động mẫu và tiếp tục phát triển nó, nó trông giống như thế này

Description: APIGateway in front of ApplicationAPI
Parameters:
NlbArn:
Type: String
Description: ARN of the NLB for ApplicationAPI
NlbDns:
Type: String
Description: DNS name of the NLB for ApplicationAPI
Stage:
Type: String
Description: Deployment Stage
Resources:
ApplicationAPIVpcLink:
Type: "AWS::ApiGateway::VpcLink"
Properties:
Description: VPC Link to ApplicationAPI NLB
Name: !Sub applicationapi-${Stage}-vpclink
TargetArns:
- !Ref NlbArn
ApplicationApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Description: API for accessing applicationAPI
EndpointConfiguration:
Types:
- REGIONAL
Name: !Sub applicationapi-${Stage}-api
Body:
swagger: "2.0"
schemes:
- "https"
paths:
/_application:
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/_application/{token}:
get:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
put:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "PUT"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/health:
get:
produces:
- "application/json"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/health
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
securityDefinitions:
sigv4:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "awsSigv4"
definitions:
Empty:
type: "object"
title: "Empty Schema"
x-amazon-apigateway-binary-media-types:
- "multipart/form-data"
ApplicationAPI4XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId: !Ref ApplicationApi
ApplicationAPI5XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId: !Ref ApplicationApi
Outputs:
ApplicationApiId:
Description: API Id
Value: !Ref ApplicationApi

Điều đầu tiên được xác định là Liên kết VPC. Đây là thứ sẽ cho phép Cổng API của bạn giao tiếp với ứng dụng đang chạy trong VPC của bạn. Nó khá đơn giản, điều duy nhất nó cần biết là NLB Arn

Tiếp theo là

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
5 của chúng tôi. Tất cả các đường dẫn của chúng tôi đều được xác định, cùng với từng động từ được hỗ trợ và loại nội dung mong đợi

Có chuyện gì với dấu gạch dưới vậy? . Chúng tôi đã sử dụng một dấu gạch dưới hàng đầu để làm nổi bật điều này

Một vài điều cần lưu ý

1. Đặt

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
7 thành
Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
8 [cũng lưu ý khối định nghĩa
Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
9 ở cuối] là thứ cho phép bạn bảo mật các tuyến đường của mình bằng quyền IAM.
2. Định nghĩa cho
Description: APIGateway in front of ApplicationAPI
Parameters:
NlbArn:
Type: String
Description: ARN of the NLB for ApplicationAPI
NlbDns:
Type: String
Description: DNS name of the NLB for ApplicationAPI
Stage:
Type: String
Description: Deployment Stage
Resources:
ApplicationAPIVpcLink:
Type: "AWS::ApiGateway::VpcLink"
Properties:
Description: VPC Link to ApplicationAPI NLB
Name: !Sub applicationapi-${Stage}-vpclink
TargetArns:
- !Ref NlbArn
ApplicationApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Description: API for accessing applicationAPI
EndpointConfiguration:
Types:
- REGIONAL
Name: !Sub applicationapi-${Stage}-api
Body:
swagger: "2.0"
schemes:
- "https"
paths:
/_application:
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/_application/{token}:
get:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
put:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "PUT"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/health:
get:
produces:
- "application/json"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/health
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
securityDefinitions:
sigv4:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "awsSigv4"
definitions:
Empty:
type: "object"
title: "Empty Schema"
x-amazon-apigateway-binary-media-types:
- "multipart/form-data"
ApplicationAPI4XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId: !Ref ApplicationApi
ApplicationAPI5XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId: !Ref ApplicationApi
Outputs:
ApplicationApiId:
Description: API Id
Value: !Ref ApplicationApi
0 KHÔNG nên có bất kỳ bảo mật nào xung quanh nó. Trình duyệt đánh nó theo quyết định của họ và không có cách nào để thêm tiêu đề ủy quyền vào yêu cầu đó. Nó phải được để mở.
3. Khối này cho phép các bài đăng dạng nhiều phần. Đây là điều mà API Gateway không hỗ trợ cho đến gần đây và là một ví dụ khác về tính năng quan trọng mà bạn có thể không nhận ra là có sẵn.

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
4

4. Cuối cùng, các khối dành cho lỗi 4XX và 5XX cho phép các lỗi được đưa vào ứng dụng chuyển đến ứng dụng khách. Mỗi lỗi được đưa ra trong ứng dụng đều thân thiện với HTTP. [Sử dụng mô-đun Boom]

Triển khai cổng API

Chúng tôi có một CFT riêng để triển khai Cổng API. Nó rất đơn giản, nó không đáng để thảo luận. Đây là mẫu trong trường hợp bạn tò mò

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
5

quyền IAM

Nói nhanh về quyền API. Bạn sẽ muốn áp dụng quyền

Description: APIGateway in front of ApplicationAPI
Parameters:
NlbArn:
Type: String
Description: ARN of the NLB for ApplicationAPI
NlbDns:
Type: String
Description: DNS name of the NLB for ApplicationAPI
Stage:
Type: String
Description: Deployment Stage
Resources:
ApplicationAPIVpcLink:
Type: "AWS::ApiGateway::VpcLink"
Properties:
Description: VPC Link to ApplicationAPI NLB
Name: !Sub applicationapi-${Stage}-vpclink
TargetArns:
- !Ref NlbArn
ApplicationApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Description: API for accessing applicationAPI
EndpointConfiguration:
Types:
- REGIONAL
Name: !Sub applicationapi-${Stage}-api
Body:
swagger: "2.0"
schemes:
- "https"
paths:
/_application:
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/_application/{token}:
get:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
put:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "PUT"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/health:
get:
produces:
- "application/json"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/health
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
securityDefinitions:
sigv4:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "awsSigv4"
definitions:
Empty:
type: "object"
title: "Empty Schema"
x-amazon-apigateway-binary-media-types:
- "multipart/form-data"
ApplicationAPI4XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId: !Ref ApplicationApi
ApplicationAPI5XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId: !Ref ApplicationApi
Outputs:
ApplicationApiId:
Description: API Id
Value: !Ref ApplicationApi
1 cho bất kỳ thứ gì cần quyền truy cập vào API này. Nó sẽ giống như thế này

Description: Load Balancer for ApplicationAPI
Parameters:
LoadBalancerArn:
Type: String
Description: ARN of a load balancer instance
Stage:
Type: String
Description: Deployment stage for this instance of ApplicationAPI
Vpc:
Type: AWS::EC2::VPC::Id
Description: VPC ID
Resources:
ApplicationAPITargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name:
!Join
- ''
- - 'applicationapi-'
- !Ref Stage
- '-targetgroup'
Port: 80
Protocol: TCP
TargetType: ip
VpcId: !Ref Vpc
ApplicationAPIListener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
DefaultActions:
- Type: forward
TargetGroupArn:
Ref: ApplicationAPITargetGroup
LoadBalancerArn:
Ref: LoadBalancerArn
Port: 80
Protocol: TCP
7

Description: APIGateway in front of ApplicationAPI
Parameters:
NlbArn:
Type: String
Description: ARN of the NLB for ApplicationAPI
NlbDns:
Type: String
Description: DNS name of the NLB for ApplicationAPI
Stage:
Type: String
Description: Deployment Stage
Resources:
ApplicationAPIVpcLink:
Type: "AWS::ApiGateway::VpcLink"
Properties:
Description: VPC Link to ApplicationAPI NLB
Name: !Sub applicationapi-${Stage}-vpclink
TargetArns:
- !Ref NlbArn
ApplicationApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Description: API for accessing applicationAPI
EndpointConfiguration:
Types:
- REGIONAL
Name: !Sub applicationapi-${Stage}-api
Body:
swagger: "2.0"
schemes:
- "https"
paths:
/_application:
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/_application/{token}:
get:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
put:
produces:
- "application/json"
parameters:
- name: "token"
in: "path"
required: true
type: "string"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/_application/{token}
requestParameters:
integration.request.path.token: "method.request.path.token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "PUT"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/health:
get:
produces:
- "application/json"
security:
- sigv4: []
x-amazon-apigateway-integration:
uri:
Fn::Sub: //${NlbDns}/health
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
connectionId:
Ref: ApplicationAPIVpcLink
httpMethod: "GET"
type: "http_proxy"
options:
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
securityDefinitions:
sigv4:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "awsSigv4"
definitions:
Empty:
type: "object"
title: "Empty Schema"
x-amazon-apigateway-binary-media-types:
- "multipart/form-data"
ApplicationAPI4XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId: !Ref ApplicationApi
ApplicationAPI5XXGatewayResponses:
Type: AWS::ApiGateway::GatewayResponse
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId: !Ref ApplicationApi
Outputs:
ApplicationApiId:
Description: API Id
Value: !Ref ApplicationApi
2 là nơi id thực tế cho API của bạn được cho là đi. Bạn có toàn quyền khóa các API của mình. Chính sách trên cấp quyền truy cập không hạn chế vào API, nhưng bạn có thể khóa mọi thứ theo tài nguyên và động từ

Sự kết luận

Rõ ràng, một vài mảnh bị thiếu. Bạn sẽ cần một ứng dụng có NLB ở phía trước và bạn vẫn cần xác định tất cả các quyền IAM của mình. Nhưng đó là những yếu tố duy nhất cho ứng dụng của bạn. Hy vọng rằng bạn có thể lấy những gì bạn đã học được ở đây và áp dụng nó vào ứng dụng của mình

Cuối cùng, nếu có bất cứ điều gì không rõ ràng, xin vui lòng cho tôi biết trong phần bình luận bên dưới. Chúng tôi hiểu việc đọc các bài đăng trên blog thiếu thông tin quan trọng mà bạn đang tìm kiếm có thể gây khó chịu như thế nào và chúng tôi muốn cung cấp thông tin toàn diện

Làm cách nào để triển khai xác thực trong API Gateway?

API Gateway hỗ trợ nhiều phương thức xác thực phù hợp với các ứng dụng và trường hợp sử dụng khác nhau. Cổng API sử dụng phương thức xác thực mà bạn chỉ định trong cấu hình dịch vụ của mình để xác thực các yêu cầu gửi đến trước khi chuyển chúng đến phần phụ trợ API của bạn .

Cổng API xử lý xác thực như thế nào?

Xác thực cổng API là một cách quan trọng để kiểm soát dữ liệu được phép truyền bằng API của bạn. Cổng API là gì? . it authenticates that a particular consumer has permission to access the API, using a predefined set of credentials.

Các loại xác thực khác nhau trong API là gì?

Các phương thức xác thực API phổ biến .
Xác thực cơ bản HTTP. Cách đơn giản nhất để xử lý xác thực là thông qua việc sử dụng HTTP, trong đó tên người dùng và mật khẩu được gửi cùng với mọi lệnh gọi API. .
Xác thực khóa API. .
Xác thực OAuth. .
Không có chứng thực

Cổng API có hỗ trợ xác thực cơ bản không?

Bạn có thể định cấu hình Cổng API để hỗ trợ Xác thực cơ bản và Cổng API hỗ trợ tích hợp với bất kỳ dịch vụ AWS nào.

Chủ Đề