<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Serverless on Robin Su</title><link>https://robinsujob.github.io/tags/serverless/</link><description>Recent content in Serverless on Robin Su</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 19 Aug 2025 00:00:00 +0800</lastBuildDate><atom:link href="https://robinsujob.github.io/tags/serverless/index.xml" rel="self" type="application/rss+xml"/><item><title>China CloudFront SSL Plugin V2 - One-Stop Free SSL Certificate Management</title><link>https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/</link><pubDate>Tue, 19 Aug 2025 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/</guid><description>&lt;img src="https://robinsujob.github.io/" alt="Featured image of post China CloudFront SSL Plugin V2 - One-Stop Free SSL Certificate Management" /&gt;&lt;p&gt;In today&amp;rsquo;s digital age, website security is paramount. SSL certificates, as a critical tool for protecting data transmission, have always been a key concern for developers and operations teams. In 2023, we released the China CloudFront SSL Plugin to facilitate the integration of free SSL certificates with CloudFront in the China region. We have continued to iterate on our solution. Now, we are pleased to announce the official release of the second generation of the China CloudFront SSL Plugin.&lt;/p&gt;
&lt;h3 id="major-upgrades"&gt;Major Upgrades
&lt;/h3&gt;&lt;p&gt;China CloudFront SSL Plugin V2 introduces three core upgrades, making certificate management simpler, safer, and more efficient.&lt;/p&gt;
&lt;h4 id="1-breaking-through-the-single-project-limitation-with-unified-multi-project-management"&gt;1. Breaking Through the Single-Project Limitation with Unified Multi-Project Management
&lt;/h4&gt;&lt;p&gt;In this new version, we have completely restructured the project management architecture:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Before (V1)&lt;/strong&gt;: Each stack could only manage a single project&amp;rsquo;s domain set. Managing multiple projects required deploying multiple stacks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;After (V2)&lt;/strong&gt;: A single stack can now manage domain sets for multiple projects, significantly simplifying operations.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="2-a-brand-new-interactive-experience--no-more-complex-operations"&gt;2. A Brand-New Interactive Experience — No More Complex Operations
&lt;/h4&gt;&lt;p&gt;To improve the user experience, we have completely redesigned the management interface:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Before (V1)&lt;/strong&gt;: An API management page built on Swagger UI that required manually constructing and sending API requests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;After (V2)&lt;/strong&gt;: An intuitive graphical user interface where all operations can be completed with simple button clicks, greatly lowering the barrier to entry.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="3-enhanced-security-mechanisms-for-safer-operations"&gt;3. Enhanced Security Mechanisms for Safer Operations
&lt;/h4&gt;&lt;p&gt;Security has been comprehensively strengthened:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Before (V1)&lt;/strong&gt;: External APIs lacked effective security validation mechanisms.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;After (V2)&lt;/strong&gt;: An Access Key verification mechanism has been introduced — all API operations now require authentication, ensuring secure and controlled access.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While introducing these new capabilities, we have preserved and reinforced the most popular features of the solution:&lt;/p&gt;
&lt;p&gt;✓ &lt;strong&gt;Cost Advantage&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fully serverless architecture with pay-per-invocation pricing&lt;/li&gt;
&lt;li&gt;Certificate renewal triggers every 30 days by default&lt;/li&gt;
&lt;li&gt;Only minimal storage and logging costs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;✓ &lt;strong&gt;Operational Automation&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Seamless integration with CloudFront&lt;/li&gt;
&lt;li&gt;Automatic replacement of associated CloudFront certificates after renewal&lt;/li&gt;
&lt;li&gt;Scheduled automatic renewal via Amazon EventBridge&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;✓ &lt;strong&gt;Operational Transparency&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Comprehensive email notification mechanism covering the entire certificate lifecycle&lt;/li&gt;
&lt;li&gt;Intuitive graphical dashboard for real-time certificate status monitoring&lt;/li&gt;
&lt;li&gt;Unified multi-project management and monitoring&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;✓ &lt;strong&gt;Open Source&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;All code is provided as open source&lt;/li&gt;
&lt;li&gt;Supports customization on top of the source code&lt;/li&gt;
&lt;li&gt;Easy to extend for enterprise-specific requirements&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These upgrades not only enhance the user experience but also provide more powerful support for China CloudFront certificate management. Whether managing certificates for a single website or multiple projects, V2 can handle it with ease.&lt;/p&gt;
&lt;h2 id="architecture"&gt;Architecture
&lt;/h2&gt;&lt;p&gt;As a certificate management solution for CloudFront in the China region, we designed a complete architecture based on serverless services, with automated deployment via Amazon CloudFormation templates.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Architecture" class="gallery-image" data-flex-basis="555px" data-flex-grow="231" height="731" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/architecture-v2.png" srcset="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/architecture-v2_hu_77ffabdb655b00f5.png 800w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/architecture-v2_hu_a1659a5a8d55333.png 1600w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/architecture-v2.png 1691w" width="1691"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Core Components:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Let&amp;rsquo;s Encrypt&lt;/strong&gt;: A free, open, and automated certificate authority that provides free SSL certificate support for the solution&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Certbot&lt;/strong&gt;: A free open-source tool for automated certificate acquisition, deployment, and renewal&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Amazon Lambda&lt;/strong&gt;: The core compute component responsible for running the certificate issuance program, frontend interface, and certificate management API&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Amazon API Gateway&lt;/strong&gt;: Provides a secure certificate management API interface — all operations require Access Key verification&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;2. Storage &amp;amp; Database:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Amazon DynamoDB&lt;/strong&gt;: A serverless database dedicated to storing project certificate issuance status and error information&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Amazon S3&lt;/strong&gt;: Used for storing backup SSL certificates, supporting certificate download and backup management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IAM SSL Certificate Storage&lt;/strong&gt;: Dedicated storage for SSL certificates associated with CloudFront — a special requirement for the China region&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;3. Automation &amp;amp; Notifications:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Amazon SNS&lt;/strong&gt;: Sends email notifications about certificate issuance status, ensuring operations teams are promptly informed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Amazon EventBridge&lt;/strong&gt;: Triggers certificate renewal on a schedule, defaulting to automatic renewal every 30 days&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="deployment-demo"&gt;Deployment Demo
&lt;/h2&gt;&lt;h4 id="create-management-stack"&gt;Create Management Stack
&lt;/h4&gt;&lt;p&gt;Creating the management stack is the first step in deploying China CloudFront SSL Plugin V2. Using an Amazon CloudFormation template, you can deploy the main stack — including Lambda functions, API Gateway, DynamoDB, and other core components — with a single click. During deployment, you need to specify a stack name and an Access Key as the API Gateway security key, ensuring only authorized users can access the certificate management features. The entire deployment process takes approximately 3–5 minutes, after which you will receive an access link to the certificate management frontend.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Create Stack" class="gallery-image" data-flex-basis="426px" data-flex-grow="177" height="720" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/new-stack.gif" srcset="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/new-stack_hu_801afb176afd33fd.gif 800w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/new-stack.gif 1280w" width="1280"&gt;&lt;/p&gt;
&lt;h4 id="create-certificate-project"&gt;Create Certificate Project
&lt;/h4&gt;&lt;p&gt;Creating a certificate project is the core step in using China CloudFront SSL Plugin V2. In the graphical management interface, you can easily create new certificate projects to request free Let&amp;rsquo;s Encrypt SSL certificates for specified domain sets. Each project supports multiple domains (comma-separated), and you can configure the notification email address and automatic renewal interval (30 days recommended). Once a project is created, the system automatically deploys a dedicated sub-stack containing a certificate issuance Lambda function and an EventBridge scheduling rule for automated certificate management.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Create Project" class="gallery-image" data-flex-basis="426px" data-flex-grow="177" height="720" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/create-project.gif" srcset="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/create-project_hu_7162baf9cd7a6cb.gif 800w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/create-project.gif 1280w" width="1280"&gt;&lt;/p&gt;
&lt;h4 id="attach-the-auto-issued-certificate-to-cloudfront"&gt;Attach the Auto-Issued Certificate to CloudFront
&lt;/h4&gt;&lt;p&gt;Attaching the auto-issued certificate to CloudFront is the key step for enabling HTTPS access. After a certificate is successfully issued, the system automatically uploads it to IAM SSL certificate storage. You can then find and select the corresponding certificate in the CloudFront console&amp;rsquo;s distribution settings. Under &amp;ldquo;Alternate Domain Names and SSL Certificate,&amp;rdquo; enter the domain name for which you requested the certificate, then select the corresponding certificate from the custom SSL certificate dropdown to complete the binding. Once bound, subsequent automatic certificate renewals will seamlessly replace the certificate in CloudFront without any manual intervention.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Attach SSL" class="gallery-image" data-flex-basis="426px" data-flex-grow="177" height="720" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/attach-ssl.gif" srcset="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/attach-ssl_hu_635e22f67d718779.gif 800w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/attach-ssl.gif 1280w" width="1280"&gt;&lt;/p&gt;
&lt;h4 id="update-certificate-project-domains--auto-renewal-interval"&gt;Update Certificate Project (Domains / Auto-Renewal Interval)
&lt;/h4&gt;&lt;p&gt;The update certificate project feature allows you to flexibly adjust project configurations to adapt to business changes. By selecting a project and clicking the &amp;ldquo;Modify Project&amp;rdquo; button, you can update the domain list and adjust the SSL certificate auto-renewal interval. Each project modification triggers a new certificate issuance, ensuring configuration changes take effect immediately. The system automatically handles CloudFront certificate updates and old certificate cleanup — the entire process is transparent to the user and reliably secure.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Update Project" class="gallery-image" data-flex-basis="426px" data-flex-grow="177" height="720" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/update-project.gif" srcset="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/update-project_hu_e4ce74cd9263387c.gif 800w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/update-project.gif 1280w" width="1280"&gt;&lt;/p&gt;
&lt;h4 id="re-issue-certificate--force-certificate-update"&gt;Re-issue Certificate / Force Certificate Update
&lt;/h4&gt;&lt;p&gt;The re-issue certificate feature gives you manual control over certificate updates. When certificate issuance fails or you need an immediate certificate update, you can select the corresponding certificate from the certificate list and click the &amp;ldquo;Re-issue&amp;rdquo; button to manually trigger the certificate update process. The system re-executes the full certificate request, validation, issuance, and CloudFront update workflow, and notifies you of the result via email. This feature is particularly useful for fault recovery, emergency updates, or testing scenarios, ensuring your SSL certificates are always up to date.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Re-issue" class="gallery-image" data-flex-basis="426px" data-flex-grow="177" height="720" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/recert.gif" srcset="https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/recert_hu_884274259bf0fe5a.gif 800w, https://robinsujob.github.io/p/china-cloudfront-ssl-plugin-v2/images/recert.gif 1280w" width="1280"&gt;&lt;/p&gt;
&lt;p&gt;To experience the full feature set, please refer to our solution page for deployment.&lt;/p&gt;
&lt;p&gt;Deploy: &lt;a class="link" href="https://console.amazonaws.cn/cloudformation/home?#/stacks/create/template?templateURL=https://aws-cn-getting-started.s3.cn-northwest-1.amazonaws.com.cn/china-cloudfront-ssl-plugin_v2/ChinaCloudFrontSslPluginStackV2.template.json" target="_blank" rel="noopener"
 &gt;One-Click Deploy China CloudFront SSL Plugin V2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Tutorial: &lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/create-ssl-with-cloudfront/" target="_blank" rel="noopener"
 &gt;China CloudFront SSL Plugin V2 Full Tutorial&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary
&lt;/h2&gt;&lt;p&gt;China CloudFront SSL Plugin V2 delivers a more convenient and comprehensive certificate solution for CloudFront users in the China region through its brand-new multi-project management architecture, intuitive graphical interface, and enhanced security mechanisms.&lt;/p&gt;
&lt;h2 id="resources-and-documentation"&gt;Resources and Documentation
&lt;/h2&gt;&lt;h3 id="tutorials--deployment"&gt;Tutorials &amp;amp; Deployment
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/create-ssl-with-cloudfront/" target="_blank" rel="noopener"
 &gt;China CloudFront SSL Plugin V2 Full Tutorial&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Detailed deployment and usage guide with complete step-by-step instructions and troubleshooting&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://console.amazonaws.cn/cloudformation/home?#/stacks/create/template?templateURL=https://aws-cn-getting-started.s3.cn-northwest-1.amazonaws.com.cn/china-cloudfront-ssl-plugin_v2/ChinaCloudFrontSslPluginStackV2.template.json" target="_blank" rel="noopener"
 &gt;One-Click Deploy V2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Deploy the latest version directly via CloudFormation template&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="open-source-repositories"&gt;Open Source Repositories
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://github.com/aws-samples/sample-China-CloudFront-SSL-Plugin-V2" target="_blank" rel="noopener"
 &gt;China CloudFront SSL Plugin V2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Complete V2 source code, supporting custom development and contributions&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://github.com/aws-samples/China-CloudFront-SSL-Plugin" target="_blank" rel="noopener"
 &gt;China CloudFront SSL Plugin V1&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First-generation source code for comparison and reference&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="mailto:china-cloudfront-ssl-plugin@amazon.com" &gt;Email the Solution Team&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Contact the China CloudFront SSL Plugin solution team directly for professional support&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://www.amazonaws.cn/support/icp/" target="_blank" rel="noopener"
 &gt;ICP Filing Guide&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Required ICP filing process for website deployment in the China region&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="related-aws-service-documentation"&gt;Related AWS Service Documentation
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://docs.amazonaws.cn/aws/latest/userguide/cloudfront.html#feature-diff" target="_blank" rel="noopener"
 &gt;Amazon CloudFront China Region Feature Differences&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Understand the special requirements and limitations of CloudFront in the China region&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://docs.amazonaws.cn/IAM/latest/UserGuide/id_credentials_server-certs.html" target="_blank" rel="noopener"
 &gt;IAM SSL Certificate Management&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Official documentation for China region CloudFront SSL certificate storage&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/migrate-domain-to-amazon-route53/" target="_blank" rel="noopener"
 &gt;Amazon Route 53 Domain Migration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Detailed steps for migrating domain resolution to Route 53&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://aws.amazon.com/cn/blogs/china/divert-website-access-traffic-from-ec2-to-amazon-cloudfront/" target="_blank" rel="noopener"
 &gt;Amazon CloudFront Deployment Guide&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;CloudFront Deployment Mini-Guide — Deploying Free Certificates with China Region CloudFront and SSL Plugin&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="other-technical-references"&gt;Other Technical References
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://letsencrypt.org/docs/" target="_blank" rel="noopener"
 &gt;Let&amp;rsquo;s Encrypt Documentation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Learn about how the Let&amp;rsquo;s Encrypt certificate authority works and its limitations&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://certbot.eff.org/pages/about" target="_blank" rel="noopener"
 &gt;Certbot Documentation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Detailed usage instructions for the Certbot tool&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://certbot-dns-route53.readthedocs.io/en/stable/" target="_blank" rel="noopener"
 &gt;Amazon Route 53 DNS Validation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Technical documentation for the Route 53 DNS validation plugin&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="contact-us"&gt;Contact Us
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="https://webchat-aws.clink.cn/chat.html?accessId=35d2504b-57b6-4093-97fd-81a6198bbbfa&amp;amp;language=zh_CN" target="_blank" rel="noopener"
 &gt;Contact AWS Technical Support&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Get official professional technical support and answers&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class="link" href="mailto:china-cloudfront-ssl-plugin@amazon.com" &gt;Email the Solution Team&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Contact the China CloudFront SSL Plugin solution team directly for professional support&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

 &lt;blockquote&gt;
 &lt;p&gt;Original: &lt;a class="link" href="https://aws.amazon.com/cn/blogs/china/china-cloudfront-ssl-plugin-v2-a-one-stop-certificate-solution-for-cloudfront-in-china-region/" target="_blank" rel="noopener"
 &gt;AWS Blog&lt;/a&gt; | &lt;a class="link" href="https://github.com/aws-samples/sample-China-CloudFront-SSL-Plugin-V2" target="_blank" rel="noopener"
 &gt;GitHub&lt;/a&gt;&lt;/p&gt;

 &lt;/blockquote&gt;</description></item><item><title>API Gateway CORS Configuration Guide</title><link>https://robinsujob.github.io/p/api-gateway-cors-configuration/</link><pubDate>Mon, 28 Oct 2024 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/api-gateway-cors-configuration/</guid><description>&lt;p&gt;CORS, or Cross-Origin Resource Sharing, is an HTTP header-based mechanism that allows servers to indicate which external origins (domains, protocols, or ports) can access their resources. CORS addresses the inconvenience caused by the same-origin policy — a browser security mechanism that restricts web pages from loading resources from different origins to prevent malicious websites from stealing sensitive data. However, this restriction also blocks legitimate cross-origin requests. Complex applications often reference third-party APIs and resources in their client-side code, and CORS is needed when the client domain does not match the server domain. Through CORS, browsers can safely perform cross-origin data transfers, bypassing the limitations of the same-origin policy. CORS allows client browsers to check with third-party servers whether a request is authorized before any data is transferred. Due to the complexity of CORS configuration, developers often set overly permissive cross-origin access permissions — for example, using &amp;ldquo;*&amp;rdquo; in allowed headers to permit all access — which can compromise application security.&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="https://aws.amazon.com/cn/api-gateway/?nc1=h_ls" target="_blank" rel="noopener"
 &gt;Amazon API Gateway&lt;/a&gt; is a fully managed service that helps developers easily manage APIs at any scale. It is commonly used for backend service management and routing. Therefore, configuring CORS on API Gateway is a very common requirement. In Amazon API Gateway, different API types have different CORS configuration methods, which adds to the complexity of CORS configuration.&lt;/p&gt;
&lt;p&gt;This article explains how to configure cross-origin resource sharing in Amazon API Gateway&amp;rsquo;s &lt;a class="link" href="https://docs.aws.amazon.com/zh_cn/apigateway/latest/developerguide/how-to-cors.html" target="_blank" rel="noopener"
 &gt;REST API&lt;/a&gt; and &lt;a class="link" href="https://docs.aws.amazon.com/zh_cn/apigateway/latest/developerguide/http-api-cors.html" target="_blank" rel="noopener"
 &gt;HTTP API&lt;/a&gt;, with a focus on the differences between REST API and HTTP API in CORS configuration, as well as how to configure CORS when authorization is enabled. By reading this article, you will master the CORS configuration techniques in Amazon API Gateway, enabling cross-origin access configurations that meet the &lt;a class="link" href="https://docs.aws.amazon.com/zh_cn/wellarchitected/latest/framework/sec_permissions_least_privileges.html" target="_blank" rel="noopener"
 &gt;principle of least privilege&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="how-cors-works"&gt;How CORS Works
&lt;/h2&gt;&lt;p&gt;CORS is an HTTP header-based mechanism where servers use header information to restrict access. CORS works primarily through the following &lt;a class="link" href="https://developer.mozilla.org/zh-CN/docs/Glossary/CORS#cors_%E6%A0%87%E5%A4%B4" target="_blank" rel="noopener"
 &gt;key HTTP headers&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Origin&lt;/strong&gt;: Indicates the request origin.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access-Control-Allow-Origin&lt;/strong&gt;: Specifies which origins can access the resource.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access-Control-Allow-Methods&lt;/strong&gt;: Lists the HTTP methods allowed to access the resource.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access-Control-Allow-Headers&lt;/strong&gt;: Indicates which custom request headers are allowed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access-Control-Allow-Credentials&lt;/strong&gt;: Indicates whether credentials such as cookies are allowed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access-Control-Max-Age&lt;/strong&gt;: Indicates how long preflight request results can be cached.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Based on the complexity of the request, CORS divides them into two categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Simple requests&lt;/strong&gt;: No preflight is needed. These requests use GET/POST/HEAD methods and only use specific safe headers (such as Accept, Content-Type).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-simple requests&lt;/strong&gt;: Preflight is required. Any cross-origin request that is not a simple request is considered a non-simple request. Before sending the actual request, the browser first sends an OPTIONS request to confirm whether the server allows the actual request. This preflight mechanism prevents unauthorized cross-origin operations from having side effects on server data.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For non-simple requests, the server relies on the browser to send a &lt;a class="link" href="https://developer.mozilla.org/zh-CN/docs/Glossary/Preflight_request" target="_blank" rel="noopener"
 &gt;CORS preflight&lt;/a&gt; or OPTIONS request. A complete request flow is as follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Complete CORS Request Flow" class="gallery-image" data-flex-basis="649px" data-flex-grow="270" height="335" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-1.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-1_hu_90f15b3de6560802.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-1.png 906w" width="906"&gt;&lt;/p&gt;
&lt;p&gt;The complete CORS flow for non-simple requests:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Client application initiates the request&lt;/li&gt;
&lt;li&gt;Browser sends the preflight request&lt;/li&gt;
&lt;li&gt;Server returns the preflight response&lt;/li&gt;
&lt;li&gt;Browser sends the actual request&lt;/li&gt;
&lt;li&gt;Server returns the actual response&lt;/li&gt;
&lt;li&gt;Client receives the actual response&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="introduction-to-api-gateway"&gt;Introduction to API Gateway
&lt;/h2&gt;&lt;p&gt;&lt;a class="link" href="https://aws.amazon.com/cn/api-gateway/?nc1=h_ls" target="_blank" rel="noopener"
 &gt;Amazon API Gateway&lt;/a&gt; is a fully managed service that helps developers easily create, publish, maintain, monitor, and secure APIs at any scale. Without the need to maintain the underlying infrastructure, API Gateway can accept and process thousands of concurrent API calls. API Gateway supports both RESTful and WebSocket API types, as well as multiple backend integration types such as containerized services, serverless workloads, and HTTP endpoints. Other key features of API Gateway include traffic management, CORS support, authorization and access control, throttling, monitoring, and API version management.&lt;/p&gt;
&lt;h3 id="rest-api-vs-http-api"&gt;REST API vs HTTP API
&lt;/h3&gt;&lt;p&gt;REST API and HTTP API are both RESTful API products of Amazon API Gateway. Their differences are as follows.&lt;/p&gt;
&lt;h4 id="features"&gt;Features
&lt;/h4&gt;&lt;p&gt;REST API&amp;rsquo;s unique features include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;API key support&lt;/li&gt;
&lt;li&gt;Per-client throttling&lt;/li&gt;
&lt;li&gt;Request validation&lt;/li&gt;
&lt;li&gt;AWS WAF integration&lt;/li&gt;
&lt;li&gt;Private API endpoints&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;HTTP API is designed with a minimalist feature set. Its characteristics include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Automatic deployment&lt;/li&gt;
&lt;li&gt;Default stage support&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="performance-and-pricing"&gt;Performance and Pricing
&lt;/h4&gt;&lt;p&gt;Because HTTP API has a more streamlined feature set, it offers faster speeds and lower prices.&lt;/p&gt;
&lt;h2 id="configuring-cors-in-api-gateway"&gt;Configuring CORS in API Gateway
&lt;/h2&gt;&lt;p&gt;To resolve cross-origin issues in Amazon API Gateway, you need to perform CORS configuration. API Gateway will automatically use the OPTIONS method and attempt to add CORS headers to existing method integration responses, which helps you handle preflight requests and actual responses. In Amazon API Gateway, REST API and HTTP API have different CORS configuration methods.&lt;/p&gt;
&lt;h3 id="rest-api-cors-configuration"&gt;REST API CORS Configuration
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;As shown in the following figure, the REST API has a default / resource, under which we created a POST method integrated with a Lambda function as the backend service.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="REST API Resource Configuration" class="gallery-image" data-flex-basis="488px" data-flex-grow="203" height="703" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-2.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-2_hu_b125e11b39350d.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-2.png 1431w" width="1431"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To configure CORS for the POST method under the / resource, we need to go back to the resource overview page and click Enable CORS.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Enable CORS Button" class="gallery-image" data-flex-basis="521px" data-flex-grow="217" height="658" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-3.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-3_hu_d101f4d084b25eb2.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-3.png 1431w" width="1431"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On the Enable CORS page, first configure the allowed methods for access control. To correctly respond to preflight requests, the OPTIONS method is enabled by default. We select the POST method that needs CORS configuration. Then, we configure the allowed headers and origins for access control — the specific allowed values depend on your backend application. Click Save after configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="CORS Configuration Page" class="gallery-image" data-flex-basis="282px" data-flex-grow="117" height="1218" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-4.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-4_hu_8f5620fe90f1d472.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-4.png 1432w" width="1432"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;After saving, on the POST method&amp;rsquo;s integration response page, you can see that in the header mapping, the Access-Control-Allow-Origin mapping value is the allowed origin configured in the previous step.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Integration Response Header Mapping" class="gallery-image" data-flex-basis="405px" data-flex-grow="169" height="846" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-5.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-5_hu_3e8077200db8ada.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-5.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the resource list, we can also see that after enabling CORS, API Gateway automatically created an OPTIONS method for us. This method is used to correctly respond to preflight requests. The OPTIONS method&amp;rsquo;s integration type is mock integration, which returns a 200 status code for requests and returns all relevant preflight response headers. The header mapping values are determined by the settings in step 3.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="OPTIONS Method Configuration" class="gallery-image" data-flex-basis="408px" data-flex-grow="170" height="839" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-6.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-6_hu_cdf3509b959456e6.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-6.png 1429w" width="1429"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Testing a cross-origin POST request from the allowed origin endpoint configured in step 3, we can see that for both the preflight request and the actual request, the REST API returns the corresponding headers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Preflight Request Response" class="gallery-image" data-flex-basis="1424px" data-flex-grow="593" height="241" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-7.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-7_hu_d46b95e540d3781a.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-7.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Actual Request Response" class="gallery-image" data-flex-basis="1926px" data-flex-grow="802" height="178" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-8.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-8_hu_dc031d25f9d16a4a.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-8.png 1429w" width="1429"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For non-root paths, you can also check CORS (Cross-Origin Resource Sharing) when creating the resource, so that API Gateway automatically creates an OPTIONS method under this resource to handle preflight requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Check CORS When Creating Resource" class="gallery-image" data-flex-basis="486px" data-flex-grow="202" height="706" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-9.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-9_hu_6be09ed5e09f6b5f.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-9.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;p&gt;Note that the OPTIONS method created using this approach will accept cross-origin requests from all origins and all methods by default. If you need to tighten the permissions, you can click Edit in the upper right corner to modify it.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Edit OPTIONS Method" class="gallery-image" data-flex-basis="612px" data-flex-grow="255" height="561" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-10.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-10_hu_c3791a9f73aa0d53.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-10.png 1431w" width="1431"&gt;&lt;/p&gt;
&lt;p&gt;After checking CORS (Cross-Origin Resource Sharing) when creating the resource, you still need to click Enable CORS in the upper right corner of the resource overview page (following the same method as step 3) to configure the CORS-related headers for the specific request method (such as POST).&lt;/p&gt;
&lt;p&gt;&lt;img alt="Configure CORS Headers for Specific Methods" class="gallery-image" data-flex-basis="1635px" data-flex-grow="681" height="210" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-11.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-11_hu_16695efaae835e00.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-11.png 1431w" width="1431"&gt;&lt;/p&gt;
&lt;h4 id="cors-configuration-with-authorization"&gt;CORS Configuration with Authorization
&lt;/h4&gt;&lt;p&gt;You can integrate &lt;a class="link" href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html" target="_blank" rel="noopener"
 &gt;Lambda authorizers&lt;/a&gt; or &lt;a class="link" href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html" target="_blank" rel="noopener"
 &gt;Cognito authorizers&lt;/a&gt; with your REST API. When enabling authorization, be sure to only enable it for the methods that need it — do not enable authorization for the OPTIONS method, otherwise preflight requests (which are unauthorized) will result in 401 errors.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Enable Authorization for POST Method" class="gallery-image" data-flex-basis="469px" data-flex-grow="195" height="730" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-12.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-12_hu_f126b76e649ca0a7.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-12.png 1428w" width="1428"&gt;&lt;/p&gt;
&lt;p&gt;Enable authorization for the POST method.&lt;/p&gt;
&lt;p&gt;&lt;img alt="OPTIONS Authorization Error" class="gallery-image" data-flex-basis="2365px" data-flex-grow="985" height="145" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-13.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-13_hu_1c92ddbc0a1b9ce1.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-13.png 1429w" width="1429"&gt;&lt;/p&gt;
&lt;p&gt;If authorization is enabled for the OPTIONS method, preflight requests will fail with errors.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Do Not Authorize OPTIONS" class="gallery-image" data-flex-basis="469px" data-flex-grow="195" height="731" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-14.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-14_hu_9207afd8a90f3ad.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-14.png 1429w" width="1429"&gt;&lt;/p&gt;
&lt;p&gt;Do not enable authorization for the OPTIONS method.&lt;/p&gt;
&lt;h3 id="http-api-cors-configuration"&gt;HTTP API CORS Configuration
&lt;/h3&gt;&lt;p&gt;In this section, we continue to use configuring CORS for the POST method under the / resource as an example to demonstrate how to configure CORS for HTTP API.&lt;/p&gt;
&lt;p&gt;HTTP API CORS configuration is relatively simple because once you enable CORS for your HTTP API, API Gateway will automatically respond to preflight requests from browsers and automatically add CORS-related headers to your backend responses. You will not see the configuration of the OPTIONS method that API Gateway uses to automatically respond to preflight requests in your API resources, nor will you see the response header configuration for the POST method.&lt;/p&gt;
&lt;p&gt;The following are the detailed steps to enable HTTP API CORS:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Go to the HTTP API page, click CORS in the left navigation bar, then click Configure in the upper right corner.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="HTTP API CORS Configuration Entry" class="gallery-image" data-flex-basis="590px" data-flex-grow="246" height="581" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-15.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-15_hu_e81433b783b1027a.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-15.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On the CORS configuration page, enter the allowed origins, headers, and methods for access control. In our example, we need to allow POST method access. Depending on your needs, you can also optionally configure exposed headers, max age, and credentials. After configuration, click Save in the lower right corner.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="HTTP API CORS Configuration Page" class="gallery-image" data-flex-basis="382px" data-flex-grow="159" height="897" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-16.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-16_hu_54f563eb5ffd4d90.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-16.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;After configuration, we cannot see the OPTIONS method configuration on the HTTP API routes page.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="HTTP API Routes Page" class="gallery-image" data-flex-basis="437px" data-flex-grow="182" height="785" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-17.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-17_hu_6a3deb6db50e33bd.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-17.png 1432w" width="1432"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Testing a cross-origin POST request from the allowed origin endpoint of the HTTP API, we can see that both the preflight OPTIONS request and the actual POST request receive correct responses. This is because API Gateway handles the HTTP API&amp;rsquo;s response to preflight requests and adds the CORS-related headers for us.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="HTTP API CORS Test Results" class="gallery-image" data-flex-basis="1875px" data-flex-grow="781" height="183" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-18.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-18_hu_63a7ec1f82bd643a.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-18.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;h4 id="cors-configuration-with-authorization-1"&gt;CORS Configuration with Authorization
&lt;/h4&gt;&lt;p&gt;Similar to REST API, HTTP API supports authorization for specific methods through &lt;a class="link" href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html" target="_blank" rel="noopener"
 &gt;Lambda&lt;/a&gt;, &lt;a class="link" href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html" target="_blank" rel="noopener"
 &gt;JWT&lt;/a&gt;, and &lt;a class="link" href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-access-control-iam.html" target="_blank" rel="noopener"
 &gt;IAM&lt;/a&gt; authorizers. If you want to enable CORS for an HTTP API with integrated authorizers, in most cases, HTTP API will automatically handle preflight requests for you. Therefore, no special configuration is needed — simply follow the steps above to enable CORS for an HTTP API with integrated authorizers. The only exception is when you create an authorized ANY method (as shown below). In this case, note that preflight requests will be handled by the ANY method rather than by HTTP API. Since preflight requests do not contain authorization information, the authorized ANY method will not return the correct status code and CORS headers, and the preflight request will fail with a 401 error.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Authorized ANY Method" class="gallery-image" data-flex-basis="724px" data-flex-grow="301" height="474" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-19.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-19_hu_6d078dcc831f02c8.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-19.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="ANY Method 401 Error" class="gallery-image" data-flex-basis="1383px" data-flex-grow="576" height="248" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-20.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-20_hu_722d8b7eaa811aee.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-20.png 1430w" width="1430"&gt;&lt;/p&gt;
&lt;p&gt;In this case, there are two solutions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;(Recommended)&lt;/strong&gt; Create a specific route for each method and resource as needed, and avoid using the ANY method. For example, in our case, we only need to create a route for the POST method.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="Create Route for Specific Method" class="gallery-image" data-flex-basis="723px" data-flex-grow="301" height="475" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-21.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-21_hu_a4f4c7744f5d9fe0.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-21.png 1432w" width="1432"&gt;&lt;/p&gt;
&lt;ol start="2"&gt;
&lt;li&gt;Create an unauthorized OPTIONS method route under the same resource path, and add any backend integration to the OPTIONS method (as shown below). This way, the unauthorized OPTIONS route will capture preflight requests.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="Create Unauthorized OPTIONS Route" class="gallery-image" data-flex-basis="504px" data-flex-grow="210" height="680" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-22.png" srcset="https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-22_hu_1e0063c55466db2f.png 800w, https://robinsujob.github.io/p/api-gateway-cors-configuration/images/cors-config-22.png 1428w" width="1428"&gt;&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary
&lt;/h2&gt;&lt;p&gt;This article introduced the CORS configuration methods for REST API and HTTP API in Amazon API Gateway, with special attention to how to configure both API types to ensure preflight requests are correctly responded to when authorization is enabled. The differences in CORS configuration between the two API types are as follows:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;API Type&lt;/th&gt;
 &lt;th&gt;CORS Configuration Method&lt;/th&gt;
 &lt;th&gt;Configuration Features&lt;/th&gt;
 &lt;th&gt;Authorization Notes&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;REST API&lt;/td&gt;
 &lt;td&gt;Configure CORS for specific routes in the REST API by clicking Enable CORS in the upper right corner of the route.&lt;/td&gt;
 &lt;td&gt;You can see the OPTIONS method used to respond to preflight requests and its response header settings under the configured route. You can also see the CORS header settings in the response of the methods that allow cross-origin access.&lt;/td&gt;
 &lt;td&gt;Do not enable authorization for the OPTIONS method.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;HTTP API&lt;/td&gt;
 &lt;td&gt;Configure CORS for the entire HTTP API by clicking CORS in the left navigation bar to enter the CORS configuration page.&lt;/td&gt;
 &lt;td&gt;Preflight requests are automatically handled by API Gateway, and the automatically responding OPTIONS method configuration is not visible in the console. CORS headers are automatically added by API Gateway, and the CORS header settings are also not visible in the response of the methods that allow cross-origin access.&lt;/td&gt;
 &lt;td&gt;Avoid using the ANY method. If you must use it, create an additional unauthorized OPTIONS method for handling preflight requests.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;To enable CORS for other AWS resources, refer to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://aws.amazon.com/cn/blogs/china/several-solutions-to-cloudfront-cross-domain-problem-cors/" target="_blank" rel="noopener"
 &gt;Enable CORS for CloudFront&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://aws.amazon.com/cn/blogs/china/several-solutions-to-cloudfront-cross-domain-problem-cors/" target="_blank" rel="noopener"
 &gt;Enable CORS for Lambda Function URLs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/cors.html" target="_blank" rel="noopener"
 &gt;Enable CORS for S3 Static Website Hosting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

 &lt;blockquote&gt;
 &lt;p&gt;Original article: &lt;a class="link" href="https://aws.amazon.com/cn/blogs/china/amazon-api-gateway-cross-origin-resource-sharing-configuration/" target="_blank" rel="noopener"
 &gt;Amazon API Gateway CORS Configuration - AWS Blog&lt;/a&gt;&lt;/p&gt;

 &lt;/blockquote&gt;</description></item></channel></rss>