最近在針對 api gateway 的部分,進行安全性的加強
有部分的 API 只希望給內部的 service 使用,就來用看看 private api gateway 的方法囉
api-gateway
2022-10-31
2022-10-21
使用 aws api-gateway 時,前面有加一層 WAF 來進行 rate limit 是一個滿好的選擇
此篇記錄 serverless framework 加上 AWS WAF 的整合方式
Tips
- 使用的 serverless plugin
Reference
- Serverless Framework: Plugins serverless plugin 說明
- Attach a WAF to API Gateway using the Serverless Framework | by Lindsey Tam | AWS Tip
- Connecting AWS WAF to API Gateway via Serverless Framework | Serverless Guru
同場加映
- 我是用 apache ab 來做 stress testing
- Artillery | Cloud-scale Testing for DevOps & SRE artillery 也可以試試看
2022-08-18
近期在修改 api-gateway 中 custom authorizer 回傳的錯誤訊息。
原本是希望可以回傳 http status code 400 的錯誤,試了一段時間後。因為是以 custom authorizer 的方式實作,在 auth 中,僅能回傳 401 & 403 的錯誤
Reference
- Introducing custom authorizers in Amazon API Gateway | AWS Compute Blog overall 的說明 blog
- awslabs/aws-apigateway-lambda-authorizer-blueprints: Blueprints and examples for Lambda-based custom Authorizers for use in API Gateway. 以這份參考,來修改 python custom authorizer 的實作
- Use API Gateway Lambda authorizers - Amazon API Gateway 使用 lambda 來實作 api-gateway custom authorizer 的說明文件
- Output from an Amazon API Gateway Lambda authorizer - Amazon API Gateway lambda authorizer 回傳的結果。
- 其中回傳 json 中,所帶的
context
資料,會傳到下個 lambda 的event
變數中
- 其中回傳 json 中,所帶的
2022-08-17
2021-12-29
用 api-gateway 為前端,來串到 ECS 中的 micro service
有關的 terraform 文件
設定 aws ecs service 時,遇到的問題
- 在設定的過程中,花滿多時間在測試要如何建立 load_balancer
- terraform-aws-ecs-fargate/main.tf at main · aws-ia/terraform-aws-ecs-fargate 這篇可以參考建立 load_balancer & security_group
- 在建立 load_balancer 時,遇到的另外一個問題是,當使用 S3 bucket 來記錄 access_log 時,有遇到權限的問題
- Enable access logs for your Classic Load Balancer - Elastic Load Balancing AWS 說明資料
- aws_elb_service_account | Data Sources | hashicorp/aws | Terraform Registry
- 參考上面的資料,加設一段
data "aws_elb_service_account" "main" {}
來設定 service account 權限 - amazon web services - Terraform - Enabling Access Load balancer logs InvalidConfigurationRequest: Access Denied for bucket - Stack Overflow 參考這篇文章,加以修改後,可以進行 access log
- Search · aws_elb_service_account 參考別人 module 的寫法
Reference
2021-11-19
在使用 api gateway 搭配 lambda 的情形中,常會遇到前端用同一組 custom domain name,不過後端需要介接不同的 serverless lambda project
目前我的作法是將 ApiGatewayRestApi & RootResourceId share 出來,提供給不同的 lambda project 使用
Reference
- Share API Gateway and API Resources 官方說明
- How to share an API domain between services in a monorepo Serverless app 滿完整的兩種做法介紹,目前是以 Method 2: Single API Gateway Project 方式來實作
- Shared API Gateway (2017-11-11)
2021-11-11
如何透過 api-gateway 將檔案上傳到 S3
Reference
- Hit the 6MB Lambda payload limit? Here’s what you can do. | theburningmonk.com - 參考 Option 1: use API Gateway service proxy
- S3 Uploads — Proxies vs Presigned URLs vs Presigned POSTs | by Zac Charles | Medium
- serverless-operations/serverless-apigateway-service-proxy: This Serverless Framewrok plugin supports the AWS service proxy integration feature of API Gateway. - This Serverless Framewrok plugin supports the AWS service proxy integration feature of API Gateway.
- Tutorial: Create a REST API as an Amazon S3 proxy in API Gateway - Amazon API Gateway 官方文件, 手動的作法參考
其他 search 到的一些記錄
2021-11-09
使用 api-gateway 來當 proxy 的方式,設定 integrationi type 為 HTTP_PROXY
需要設定 AWS::ApiGateway::Resource
& AWS::ApiGateway::Method
,當設定的 url 為多層的 (包含多個 / 的 path),需要設定多組 AWS::ApiGateway::Resource
serverless framework plugin
- serverless-operations/serverless-apigateway-service-proxy: This Serverless Framewrok plugin supports the AWS service proxy integration feature of API Gateway. - This Serverless Framewrok plugin supports the AWS service proxy integration feature of API Gateway.
Reference
- Setting an HTTP Proxy on API Gateway serverless framework 說明文件
- Tutorial: Build a REST API with HTTP proxy integration - Amazon API Gateway ** 手動建立的文件,可以先用這份來嘗試
- Build an API with HTTP Proxy via Serverless | by Kithmal Warnasooriya | Medium 主要參考文章
- Setting an HTTP Proxy on API Gateway by using Serverless framework. 主要參考文章
- Working with routes for HTTP APIs - Amazon API Gateway routing 的順序
- Amazon API Gateway: Explaining HTTP Proxy in HTTP API | by Jaewoo Ahn | Sep, 2021 | Medium
同場加映
- ServerlessOperations 在看 apigateway service proxy 時,有看到是這家日本公司開發的 project,來加以關注囉
2021-11-01
在 AWS 上使用 managed reverse proxy 方式
- AWS Amplify Console
- API Gateway
- Amazon CloudFront with Lambda@Edge
Reference
2021-01-14
最近遇到一個 api-gateway 回 401 的情形,追查之後覺得有可能是 identity sources 傳空值造成的
- For request parameter-based authorizers, the error generally occurs when configured identity sources are missing, null, empty, or invalid.