<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>AWS on Robin Su</title><link>https://robinsujob.github.io/categories/aws/</link><description>Recent content in AWS 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/categories/aws/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>Deploy GGUF Models on Amazon SageMaker with llama.cpp</title><link>https://robinsujob.github.io/p/sagemaker-gguf-model-inference/</link><pubDate>Wed, 12 Feb 2025 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/sagemaker-gguf-model-inference/</guid><description>&lt;img src="https://robinsujob.github.io/" alt="Featured image of post Deploy GGUF Models on Amazon SageMaker with llama.cpp" /&gt;&lt;p&gt;With the rapid development of artificial intelligence, LLM models have demonstrated powerful capabilities in natural language processing, machine translation, and intelligent assistants. These models are typically developed using frameworks like PyTorch, with pre-trained results stored in specific binary formats such as PyTorch&amp;rsquo;s .pt files. However, as model sizes continue to grow, traditional file formats face challenges in storage, transmission, and loading — large file sizes, slow loading speeds, and poor cross-platform compatibility.&lt;/p&gt;
&lt;p&gt;To address these challenges, &lt;a class="link" href="https://github.com/ggerganov/ggml/blob/master/docs/gguf.md" target="_blank" rel="noopener"
 &gt;GGUF&lt;/a&gt; (GPT-Generated Unified Format) was created. GGUF is a binary file format designed specifically for LLM models, proposed by Georgi Gerganov, the founder of the llama.cpp open-source project. It aims to improve the storage and exchange efficiency of large models through optimized data structures, compact binary encoding, and memory mapping. GGUF format is now widely used in deploying and sharing various large models, especially popular in open-source communities like Hugging Face.&lt;/p&gt;
&lt;p&gt;Its core features enable developers to manage and use LLM models more efficiently while reducing resource consumption and improving performance. Through conversion tools, original model pre-training results can be easily converted to GGUF format for a more efficient experience.&lt;/p&gt;
&lt;p&gt;In this article, you will learn how to deploy LLM models in GGUF file format using Amazon SageMaker AI real-time inference endpoints.&lt;/p&gt;
&lt;h2 id="amazon-sagemaker-ai-model-deployment-options"&gt;Amazon SageMaker AI Model Deployment Options
&lt;/h2&gt;&lt;p&gt;&lt;a class="link" href="https://aws.amazon.com/cn/sagemaker-ai/" target="_blank" rel="noopener"
 &gt;Amazon SageMaker AI&lt;/a&gt; is a fully managed service that brings together a broad set of tools to enable high-performance, low-cost machine learning (ML) for any use case. With SageMaker AI, you can build, train, and deploy ML models at scale using notebooks, debuggers, profilers, pipelines, MLOps, and more. It supports built-in algorithms and pre-built Docker images for common ML frameworks (TensorFlow, PyTorch, ONNX, XGBoost), and provides specialized Deep Learning Containers (DLC), libraries, and tools for model parallelism and Large Model Inference (LMI).&lt;/p&gt;
&lt;p&gt;If the pre-built Docker images don&amp;rsquo;t meet your needs, you can build your own Docker container (BYOC – Bring Your Own Container) for inference. To be compatible with SageMaker AI, your container must:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Have a web server listening on port 8080.&lt;/li&gt;
&lt;li&gt;Accept POST requests to /invocations and /ping endpoints. Requests must return within 60 seconds with a maximum size of 6 MB.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To deploy and run GGUF models in SageMaker AI, you need to build a custom Docker container. This approach integrates the llama.cpp project to run GGUF models for effective deployment and inference on the SageMaker AI platform.&lt;/p&gt;
&lt;h2 id="llamacpp-and-gguf"&gt;llama.cpp and GGUF
&lt;/h2&gt;&lt;p&gt;&lt;a class="link" href="https://github.com/ggerganov/llama.cpp" target="_blank" rel="noopener"
 &gt;llama.cpp&lt;/a&gt; is a C/C++ LLM inference project designed for local or cloud-based LLM inference with minimal setup and optimal performance across various hardware. Key advantages include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pure C/C++ implementation with no dependencies&lt;/li&gt;
&lt;li&gt;First-class support for Apple silicon, optimized via ARM NEON, Accelerate, and Metal frameworks&lt;/li&gt;
&lt;li&gt;AVX, AVX2, AVX512, and AMX support for x86 architectures&lt;/li&gt;
&lt;li&gt;Multiple quantization options (from 5-bit to 8-bit) for faster inference and lower memory usage&lt;/li&gt;
&lt;li&gt;Multiple GPU backend support including NVIDIA (CUDA), AMD (HIP), and Moore Threads MTT (MUSA)&lt;/li&gt;
&lt;li&gt;CPU+GPU hybrid inference, enabling partial acceleration for models larger than VRAM capacity&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To run in llama.cpp, models must be stored in GGUF format. You can run GGUF models through llama.cpp containers, leveraging its full capabilities. When running GGUF models in SageMaker, combining them with llama.cpp maximizes its efficient inference capabilities and multi-hardware architecture support.&lt;/p&gt;
&lt;h2 id="hosting-gguf-models-in-sagemaker-ai-using-byoc"&gt;Hosting GGUF Models in SageMaker AI Using BYOC
&lt;/h2&gt;&lt;p&gt;The following section details how to combine GGUF with llama.cpp using Amazon SageMaker AI. We&amp;rsquo;ll demonstrate how to build a dedicated GGUF Docker container for SageMaker AI and apply it to model inference.&lt;/p&gt;
&lt;p&gt;Using the &lt;a class="link" href="https://docs.aws.amazon.com/sagemaker/latest/dg/adapt-inference-container.html" target="_blank" rel="noopener"
 &gt;Bring Your Own Container (BYOC)&lt;/a&gt; approach, Amazon SageMaker AI provides great flexibility. Regardless of programming language, runtime, framework, or dependencies, you can integrate virtually any model and code into the SageMaker AI ecosystem.&lt;/p&gt;
&lt;p&gt;This article uses &lt;a class="link" href="https://aws.amazon.com/sagemaker-ai/notebooks/" target="_blank" rel="noopener"
 &gt;Amazon SageMaker AI Notebook&lt;/a&gt; to build and deploy the GGUF model runtime framework. The solution architecture is shown below.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Solution Architecture" class="gallery-image" data-flex-basis="344px" data-flex-grow="143" 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/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai1.jpg" srcset="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai1_hu_77d54a03e10f814.jpg 800w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai1.jpg 976w" width="976"&gt;&lt;/p&gt;
&lt;p&gt;The main steps are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;From HuggingFace, download a GGUF model and upload it to S3. This blog uses Llama 3 8B GGUF as an example.&lt;/li&gt;
&lt;li&gt;Prepare the key BYOC files in the Notebook: Dockerfile, main.py, requirements.txt, serve, server.sh.&lt;/li&gt;
&lt;li&gt;Create a custom Docker image and push it to Amazon ECR.&lt;/li&gt;
&lt;li&gt;Create an Amazon SageMaker Model in the Notebook and deploy it to an inference endpoint.&lt;/li&gt;
&lt;li&gt;During endpoint startup, download the GGUF model from S3 to the specified location in the container.&lt;/li&gt;
&lt;li&gt;Test the endpoint by invoking inference with the SageMaker SDK.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="1-create-amazon-sagemaker-ai-notebook"&gt;1. Create Amazon SageMaker AI Notebook
&lt;/h3&gt;&lt;p&gt;You can create a SageMaker AI Notebook instance in the AWS console, selecting an appropriate instance type and storage. Note that disk space of 30GB or more is recommended, primarily for container building and model storage.&lt;/p&gt;
&lt;p&gt;When selecting or creating an IAM role, ensure the role has permissions to push images to Amazon ECR.&lt;/p&gt;
&lt;p&gt;If the permissions are missing, add the following inline policy:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Notebook Creation" class="gallery-image" data-flex-basis="242px" data-flex-grow="101" height="1703" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai2.jpg" srcset="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai2_hu_f3ed2e041fdb6436.jpg 800w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai2_hu_37b333e052ca44e0.jpg 1600w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai2.jpg 1722w" width="1722"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="IAM Permissions" class="gallery-image" data-flex-basis="292px" data-flex-grow="121" height="1249" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai3.jpg" srcset="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai3_hu_8314466b84e5192e.jpg 800w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai3.jpg 1521w" width="1521"&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;Effect&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Allow&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;Action&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ecr:CompleteLayerUpload&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ecr:UploadLayerPart&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ecr:InitiateLayerUpload&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ecr:BatchCheckLayerAvailability&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ecr:PutImage&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ecr:BatchGetImage&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;],&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;Resource&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;arn:aws:ecr:*:*:*&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h3 id="2-build-byoc-code"&gt;2. Build BYOC Code
&lt;/h3&gt;&lt;p&gt;The complete code is available in the &lt;a class="link" href="https://github.com/aws-samples/deploy-gguf-model-to-sagemaker" target="_blank" rel="noopener"
 &gt;aws-samples repository&lt;/a&gt;. This article covers key code explanations only.&lt;/p&gt;
&lt;p&gt;To run GGUF models in SageMaker, prepare the code with the following file structure:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;workspace
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;|-- Dockerfile
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;|-- main.py
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;|-- requirements.txt
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;|-- serve
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;|-- server.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The runtime trigger logic and HTTP requests are shown below.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Runtime Logic" class="gallery-image" data-flex-basis="287px" data-flex-grow="119" height="401" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai4.png" width="481"&gt;&lt;/p&gt;
&lt;h4 id="21-dockerfile"&gt;2.1 Dockerfile
&lt;/h4&gt;&lt;p&gt;The Dockerfile defines a container environment based on the llama.cpp CUDA version, designed specifically for running GGUF models on SageMaker.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;span class="lnt"&gt;24
&lt;/span&gt;&lt;span class="lnt"&gt;25
&lt;/span&gt;&lt;span class="lnt"&gt;26
&lt;/span&gt;&lt;span class="lnt"&gt;27
&lt;/span&gt;&lt;span class="lnt"&gt;28
&lt;/span&gt;&lt;span class="lnt"&gt;29
&lt;/span&gt;&lt;span class="lnt"&gt;30
&lt;/span&gt;&lt;span class="lnt"&gt;31
&lt;/span&gt;&lt;span class="lnt"&gt;32
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-dockerfile" data-lang="dockerfile"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;ghcr.io/ggerganov/llama.cpp:full-cuda&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;PYTHONUNBUFFERED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;MODELPATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/app/llm_model.bin&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;:/app&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;BUCKET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;BUCKET_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;/app&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;RUN&lt;/span&gt; apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get install -y &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; unzip &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; libcurl4-openssl-dev &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; python3 &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; python3-pip &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; python3-dev &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; git &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; psmisc &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; pciutils&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; requirements.txt ./requirements.txt&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; main.py /app/&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; serve /app/&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;COPY&lt;/span&gt; server.sh /app/&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;RUN&lt;/span&gt; chmod u+x serve&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;RUN&lt;/span&gt; chmod u+x server.sh&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;RUN&lt;/span&gt; pip3 install -r requirements.txt&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;RUN&lt;/span&gt; &lt;span class="nb"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/app:&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;/bin/bash&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;8080&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;When building the Dockerfile, pay attention to these key environment variables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;MODELPATH&lt;/strong&gt;: Specifies the model filename used at startup.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BUCKET&lt;/strong&gt; and &lt;strong&gt;BUCKET_KEY&lt;/strong&gt;: Define the Amazon S3 bucket name and object key for the model file.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="22-mainpy"&gt;2.2 main.py
&lt;/h4&gt;&lt;p&gt;This file implements an HTTP API server for interacting with llama.cpp. Key modifications for SageMaker deployment include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Port configuration: main.py defaults to port 8080, connecting to llama.cpp on port 8081&lt;/li&gt;
&lt;li&gt;Route changes: /v1/completions changed to /invocations, added /ping health check&lt;/li&gt;
&lt;li&gt;Model loading: Added update_model function for automatic S3 model download&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;s3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;s3&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;download_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;MODELPATH&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;/app/server.sh&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;MODELPATH&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;traceback&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;format_exc&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;/ping&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;GET&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;ping&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;/invocations&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;POST&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;is_present&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;configure&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;update_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;configure&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;bucket&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;configure&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;key&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="o"&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h4 id="23-sagemaker-inference-entry-point-serve-file"&gt;2.3 SageMaker Inference Entry Point: serve File
&lt;/h4&gt;&lt;p&gt;SageMaker inference nodes execute &lt;code&gt;docker run image serve&lt;/code&gt; by default when starting containers.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/bin/sh
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;serve&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;uvicorn &lt;span class="s1"&gt;&amp;#39;main:asgi_app&amp;#39;&lt;/span&gt; --host 0.0.0.0 --port &lt;span class="m"&gt;8080&lt;/span&gt; --workers &lt;span class="m"&gt;8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h4 id="24-llamacpp-startup-script-serversh"&gt;2.4 llama.cpp Startup Script: server.sh
&lt;/h4&gt;&lt;p&gt;server.sh starts the llama.cpp service. See the &lt;a class="link" href="https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md" target="_blank" rel="noopener"
 &gt;llama.cpp documentation&lt;/a&gt; for available runtime parameters.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/bin/sh
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;server.sh&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;args: &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;GPU Layer: &lt;/span&gt;&lt;span class="nv"&gt;$GPU_LAYERS&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; lspci &lt;span class="p"&gt;|&lt;/span&gt; grep -i nvidia &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&amp;gt; /dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;NVIDIA GPU is available.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;NGL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$GPU_LAYERS&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;CPU_PER_SLOT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;No NVIDIA GPU found.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;NGL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;CPU_PER_SLOT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;killall llama-server
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/app/llama-server -m &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; -c &lt;span class="m"&gt;2048&lt;/span&gt; -t &lt;span class="k"&gt;$(&lt;/span&gt;nproc --all&lt;span class="k"&gt;)&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --host 0.0.0.0 --port &lt;span class="m"&gt;8081&lt;/span&gt; -cb &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; -np &lt;span class="k"&gt;$(($(&lt;/span&gt;nproc --all&lt;span class="k"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;$CPU_PER_SLOT&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt; -ngl &lt;span class="nv"&gt;$NGL&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h3 id="3-model-deployment-and-testing"&gt;3. Model Deployment and Testing
&lt;/h3&gt;&lt;p&gt;During model deployment, specify the ECR image, instance type, and corresponding environment variables.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;container_uri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ECR_REPOSITORY_URI&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;IMAGE_TAG&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;instance_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;ml.g5.2xlarge&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sagemaker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utils&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name_from_base&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;llama-cpp-gguf-byoc&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sagemaker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;image_uri&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;container_uri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;iam_role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;MODELPATH&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;/app/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;MODEL_NAME&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;BUCKET&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;S3_BUCKET_NAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;BUCKET_KEY&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;MODEL_NAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;GPU_LAYERS&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;32&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;instance_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;instance_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;initial_instance_count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;During inference, you can pass parameters to get model output. Standard invocation:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;invoke_sagemaker_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;llama_args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sagemaker_runtime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;invoke_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;EndpointName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;llama_args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;ContentType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;response_body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Body&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response_body&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;llama_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;prompt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;What are the most popular tourist attractions in Beijing?&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;max_tokens&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;temperature&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;repeat_penalty&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;frequency_penalty&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;top_p&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;inference&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;invoke_sagemaker_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;llama_args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inference&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;choices&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;text&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Streaming output:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;span class="lnt"&gt;24
&lt;/span&gt;&lt;span class="lnt"&gt;25
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;invoke_sagemaker_streaming_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;llama_args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sagemaker_runtime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;invoke_endpoint_with_response_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;EndpointName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;llama_args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;ContentType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;event_stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Body&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;event_stream&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;itm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;PayloadPart&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Bytes&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strict&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;choices&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;text&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;llama_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;prompt&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;What are the most popular tourist attractions in Beijing?&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;max_tokens&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;temperature&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;repeat_penalty&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;frequency_penalty&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;top_p&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;stream&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;invoke_sagemaker_streaming_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;llama_args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;You can pass S3 bucket name and object key to the SageMaker AI inference instance for dynamic model replacement at runtime:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;configure&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;bucket&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;S3_BUCKET_NAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;key&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;MODEL_NAME&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sagemaker_runtime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;invoke_endpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;EndpointName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;endpoint_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;ContentType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;Body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;response: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The inference results after deployment are shown below.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Inference Results" class="gallery-image" data-flex-basis="483px" data-flex-grow="201" height="1648" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai5.jpg" srcset="https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai5_hu_8c8e6cd9d8315636.jpg 800w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai5_hu_96443b5ae743182f.jpg 1600w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai5_hu_31cf501a671b939e.jpg 2400w, https://robinsujob.github.io/p/sagemaker-gguf-model-inference/images/practice-running-gguf-format-model-inference-using-sagemaker-ai5.jpg 3322w" width="3322"&gt;&lt;/p&gt;
&lt;p&gt;After testing, if you no longer need the inference endpoint, delete the Endpoint resources to avoid unnecessary charges.&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary
&lt;/h2&gt;&lt;p&gt;This article demonstrated how to deploy GGUF format models on Amazon SageMaker AI inference endpoints using the Bring Your Own Container (BYOC) approach via SageMaker AI Notebook. After successful deployment, you can seamlessly integrate the model with other AWS services and embed it into your applications to build feature-rich AI applications.&lt;/p&gt;
&lt;h2 id="references"&gt;References
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;&lt;a class="link" href="https://github.com/ggerganov/ggml/blob/master/docs/gguf.md" target="_blank" rel="noopener"
 &gt;GGUF Specification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://github.com/ggerganov/llama.cpp" target="_blank" rel="noopener"
 &gt;llama.cpp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://aws.amazon.com/cn/sagemaker/" target="_blank" rel="noopener"
 &gt;Amazon SageMaker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.aws.amazon.com/sagemaker/latest/dg/adapt-inference-container.html" target="_blank" rel="noopener"
 &gt;Adapting Your Own Inference Container&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://sagemaker-examples.readthedocs.io/en/latest/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.html" target="_blank" rel="noopener"
 &gt;SageMaker BYOC Examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://github.com/ggerganov/llama.cpp/blob/gguf-python/examples/server/api_like_OAI.py" target="_blank" rel="noopener"
 &gt;llama.cpp API Example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://github.com/aws-samples/genai-llm-cpu-sagemaker/tree/main/docker" target="_blank" rel="noopener"
 &gt;GenAI LLM CPU SageMaker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://community.aws/content/2eazHYzSfcY9flCGKsuGjpwqq1B" target="_blank" rel="noopener"
 &gt;Community AWS Article&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;

 &lt;blockquote&gt;
 &lt;p&gt;Original post: &lt;a class="link" href="https://aws.amazon.com/cn/blogs/china/practice-running-gguf-format-model-inference-using-sagemaker-ai/" target="_blank" rel="noopener"
 &gt;Practice Running GGUF Format Model Inference Using SageMaker AI&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub repo: &lt;a class="link" href="https://github.com/aws-samples/deploy-gguf-model-to-sagemaker" target="_blank" rel="noopener"
 &gt;aws-samples/deploy-gguf-model-to-sagemaker&lt;/a&gt;&lt;/p&gt;

 &lt;/blockquote&gt;</description></item><item><title>From GPT-SoVITS to AWS MagicVoice: Building a Custom-Voice TTS Solution</title><link>https://robinsujob.github.io/p/aws-magicvoice-gpt-sovits-solution/</link><pubDate>Sun, 01 Dec 2024 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/aws-magicvoice-gpt-sovits-solution/</guid><description>&lt;p&gt;Around 2024, GPT-SoVITS quickly gained traction in the open-source speech community. It made custom voice creation—previously a highly specialized undertaking—accessible to everyday developers. The official project supports &lt;strong&gt;zero-shot TTS from roughly five seconds of reference audio&lt;/strong&gt;, as well as &lt;strong&gt;few-shot fine-tuning with about one minute of speech&lt;/strong&gt;. It can also use a reference voice to synthesize speech across languages, including Chinese, English, and Japanese.&lt;/p&gt;
&lt;p&gt;Its popularity stems not only from its output quality, but also from a WebUI that brings together data segmentation, speech recognition, text annotation, training, and inference tools. This toolchain is highly efficient for model developers. However, new challenges emerge when the system is handed to real business users: the interface is complex, model files require manual management, the frontend and backend are tightly coupled, and deployment and operations require expertise in GPUs, Linux, and model directory structures.&lt;/p&gt;
&lt;p&gt;This was the starting point for &lt;strong&gt;MagicVoice&lt;/strong&gt;: packaging GPT-SoVITS as a ready-to-use, manageable reference solution deployed in the customer&amp;rsquo;s own AWS account.&lt;/p&gt;
&lt;h2 id="from-gpt-sovitss-popularity-to-an-aws-solution"&gt;From GPT-SoVITS&amp;rsquo;s Popularity to an AWS Solution
&lt;/h2&gt;&lt;p&gt;The customer wanted to use custom voices for audiobook production and similar content workflows. The requirement went well beyond simply “reading text aloud”:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Provide multiple characters and emotions within one system;&lt;/li&gt;
&lt;li&gt;Create character voices quickly from a small number of samples;&lt;/li&gt;
&lt;li&gt;Generate Chinese, English, or mixed Chinese-English content with the same character;&lt;/li&gt;
&lt;li&gt;Keep end users from having to understand model weights or complex inference parameters;&lt;/li&gt;
&lt;li&gt;Allow model developers to train, update, and manage voices independently;&lt;/li&gt;
&lt;li&gt;Enable rapid environment deployment, with straightforward maintenance or decommissioning after testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The native GPT-SoVITS WebUI is built with Gradio and offers a comprehensive feature set, but it combines model development, data processing, and end-user inference in a single interface. Nontechnical users face too many options, while solution maintainers cannot readily host it as a static website on Amazon S3 and Amazon CloudFront.&lt;/p&gt;
&lt;p&gt;MagicVoice therefore focused on four goals:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;One-click infrastructure deployment&lt;/strong&gt;: Use AWS CDK to generate an AWS CloudFormation template.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A user-friendly interface&lt;/strong&gt;: Build a new frontend that exposes only essential options.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cloud-based model management&lt;/strong&gt;: Host models in Amazon S3 to simplify the deployment of characters, emotions, and reference voices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Separation of developers and users&lt;/strong&gt;: Developers handle training, models, and voice licensing; users simply choose a voice and generate audio.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This adds a productization layer beyond merely moving the WebUI to Amazon EC2—and that layer is central to the value of the solution.&lt;/p&gt;
&lt;h2 id="magicvoice-architecture-on-aws"&gt;MagicVoice Architecture on AWS
&lt;/h2&gt;&lt;p&gt;The following diagram shows the overall MagicVoice architecture on AWS and its three core flows: frontend access, speech inference, and model updates.&lt;/p&gt;
&lt;figure&gt;
 &lt;img src="https://robinsujob.github.io/media/magicvoice/architecture-original.png" alt="Overall MagicVoice architecture on AWS" loading="lazy"&gt;
 &lt;figcaption&gt;Overall MagicVoice architecture on AWS&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The architecture consists of three main components: &lt;strong&gt;the web frontend, the inference backend, and the model synchronization and update service&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id="1-web-frontend"&gt;1. Web Frontend
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;The frontend is built with React and AWS Cloudscape;&lt;/li&gt;
&lt;li&gt;Compiled static assets are stored in Amazon S3;&lt;/li&gt;
&lt;li&gt;Amazon CloudFront serves as the unified access point and distributes the frontend content;&lt;/li&gt;
&lt;li&gt;The interface exposes only text, character, emotion, language, speed, and a small set of advanced inference options;&lt;/li&gt;
&lt;li&gt;The “Reload TTS Service” action enters the backend event flow through Amazon API Gateway.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cloudscape offers more than visual consistency. It allows the frontend to be released independently of Gradio and the model process, so end users never need to see developer-oriented functions such as training, audio segmentation, or weight paths.&lt;/p&gt;
&lt;h3 id="2-inference-backend"&gt;2. Inference Backend
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;The GPT-SoVITS inference service runs on a GPU-enabled Amazon EC2 instance;&lt;/li&gt;
&lt;li&gt;CloudFront forwards inference requests to the EC2 backend;&lt;/li&gt;
&lt;li&gt;The EC2 instance reads characters, emotions, model weights, and reference audio from the model S3 bucket;&lt;/li&gt;
&lt;li&gt;The inference API supports both standard responses and streaming output.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A proof-of-concept environment can start with a &lt;code&gt;g4dn.xlarge&lt;/code&gt; instance. Production instance sizing, however, should be benchmarked against the model version, concurrency, time to first audio output, audio duration, and GPU memory consumption.&lt;/p&gt;
&lt;h3 id="3-model-synchronization-and-update-service"&gt;3. Model Synchronization and Update Service
&lt;/h3&gt;&lt;p&gt;Model updates can be triggered in two ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A model developer uploads or deletes model files in Amazon S3, and the resulting S3 event is sent to Amazon EventBridge;&lt;/li&gt;
&lt;li&gt;An authorized user selects the reload action in the frontend, causing Amazon API Gateway to send an event to EventBridge.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;EventBridge then invokes AWS Systems Manager Run Command. Using a predefined Systems Manager document, Run Command executes synchronization and reload scripts on the EC2 instance. The scripts synchronize the latest models from Amazon S3 to the inference instance and then refresh the service.&lt;/p&gt;
&lt;p&gt;As a result, model developers do not need to sign in to the EC2 instance or copy weights manually. The inference instance does not need to expose SSH, and routine management is handled through Amazon S3, EventBridge, and Systems Manager.&lt;/p&gt;
&lt;h2 id="why-separate-model-developers-from-end-users"&gt;Why Separate Model Developers from End Users?
&lt;/h2&gt;&lt;p&gt;A custom-voice solution serves two fundamentally different groups:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Role&lt;/th&gt;
 &lt;th&gt;Responsibilities&lt;/th&gt;
 &lt;th&gt;What They Do Not Need to Handle&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Model developer&lt;/td&gt;
 &lt;td&gt;Prepare licensed source material, train models, organize directories, upload to Amazon S3, and validate voice quality&lt;/td&gt;
 &lt;td&gt;The business-facing interface and routine text generation&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;End user&lt;/td&gt;
 &lt;td&gt;Select a character, emotion, and language; enter text; preview or download the result&lt;/td&gt;
 &lt;td&gt;Weight files, training parameters, GPUs, or server operations&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This separation improves usability and clarifies responsibility for voice rights and operations. Whether voice material is properly licensed and whether a model may be used commercially should be addressed in the model release process—not decided ad hoc by end users at inference time.&lt;/p&gt;
&lt;p&gt;The MagicVoice frontend therefore exposes only the options required by the business workflow:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TTS Text;&lt;/li&gt;
&lt;li&gt;Character;&lt;/li&gt;
&lt;li&gt;Emotion;&lt;/li&gt;
&lt;li&gt;Language;&lt;/li&gt;
&lt;li&gt;Speed;&lt;/li&gt;
&lt;li&gt;Inference Batch;&lt;/li&gt;
&lt;li&gt;Top K, Top P, Temperature;&lt;/li&gt;
&lt;li&gt;Streaming;&lt;/li&gt;
&lt;li&gt;Reload TTS Service.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
 &lt;img src="https://robinsujob.github.io/media/magicvoice/demo-ui.png" alt="MagicVoice demo interface" loading="lazy"&gt;
 &lt;figcaption&gt;The streamlined MagicVoice user interface built with AWS Cloudscape&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="the-model-lifecycle-from-training-to-production"&gt;The Model Lifecycle: From Training to Production
&lt;/h2&gt;&lt;p&gt;GPT-SoVITS models used to generate different character voices require a consistent directory structure for GPT weights, SoVITS weights, reference audio, reference text, and language metadata. The basic workflow is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Prepare and train a voice model in a separate training environment;&lt;/li&gt;
&lt;li&gt;Organize the model according to the MagicVoice directory convention;&lt;/li&gt;
&lt;li&gt;Upload the model directory to the model storage S3 bucket;&lt;/li&gt;
&lt;li&gt;An S3 event triggers EventBridge;&lt;/li&gt;
&lt;li&gt;EventBridge invokes Systems Manager Run Command;&lt;/li&gt;
&lt;li&gt;The EC2 instance synchronizes the model and reloads the inference service;&lt;/li&gt;
&lt;li&gt;After refreshing the character list, users can select the new voice.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Training and online inference should run in separate environments. Start GPU instances on demand for model training, then publish the resulting models to Amazon S3 so that training workloads do not consume online inference capacity.&lt;/p&gt;
&lt;p&gt;For consistent management of character voices and emotions, organize directories by character and model version, and store the model weights, reference audio, and inference configuration together in each directory.&lt;/p&gt;
&lt;figure&gt;
 &lt;img src="https://robinsujob.github.io/media/magicvoice/model-directory.png" alt="Example MagicVoice character model directory containing reference audio, infer_config.json, GPT weights, and SoVITS weights" loading="lazy"&gt;
 &lt;figcaption&gt;Example character model directory&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The &lt;code&gt;infer_config.json&lt;/code&gt; file is the entry point for each character model&amp;rsquo;s inference configuration. It records the locations of the GPT and SoVITS weight files, while &lt;code&gt;emotion_list&lt;/code&gt; maps emotion labels such as “default” and “angry” to the corresponding reference audio (&lt;code&gt;ref_wav_path&lt;/code&gt;), reference text (&lt;code&gt;prompt_text&lt;/code&gt;), and language (&lt;code&gt;prompt_language&lt;/code&gt;). After a user selects a character and emotion in the frontend, the inference service uses this configuration to load the appropriate model weights and reference audio, eliminating the need to maintain each file path in application code.&lt;/p&gt;
&lt;p&gt;Each model version should include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An &lt;code&gt;infer_config.json&lt;/code&gt; inference configuration file;&lt;/li&gt;
&lt;li&gt;GPT and SoVITS model weights;&lt;/li&gt;
&lt;li&gt;Reference audio for each emotion, together with its text and language metadata;&lt;/li&gt;
&lt;li&gt;The model version and release date.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="ready-to-use-deployment-with-infrastructure-as-code"&gt;Ready-to-Use Deployment with Infrastructure as Code
&lt;/h2&gt;&lt;p&gt;MagicVoice uses Amazon CloudFront, Amazon S3, Amazon EC2, Amazon API Gateway, Amazon EventBridge, AWS Systems Manager, and AWS Identity and Access Management (IAM). Creating these resources manually in the console would not only slow deployment, but also make it difficult to maintain consistency across environments. This solution uses infrastructure as code (IaC) to deploy and manage the complete solution framework.&lt;/p&gt;
&lt;p&gt;The infrastructure template creates and connects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A frontend S3 bucket;&lt;/li&gt;
&lt;li&gt;A model S3 bucket;&lt;/li&gt;
&lt;li&gt;A CloudFront distribution;&lt;/li&gt;
&lt;li&gt;A GPU-enabled EC2 instance, Amazon EBS volumes, a security group, and an instance role;&lt;/li&gt;
&lt;li&gt;An API Gateway reload API;&lt;/li&gt;
&lt;li&gt;EventBridge rules;&lt;/li&gt;
&lt;li&gt;A Systems Manager document;&lt;/li&gt;
&lt;li&gt;The required IAM roles and policies.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Permissions follow the principle of least privilege: the EC2 instance can read only the designated model bucket; EventBridge can invoke only the designated Systems Manager document; Run Command targets only the intended instance; and the frontend reload API must not allow anonymous access.&lt;/p&gt;
&lt;h2 id="demo-from-text-input-to-speech-generation"&gt;Demo: From Text Input to Speech Generation
&lt;/h2&gt;&lt;p&gt;The following video demonstrates the complete MagicVoice workflow in about three minutes, including character and parameter selection, speech generation, and output preview.&lt;/p&gt;
&lt;video controls preload="metadata" poster="/media/magicvoice/demo-ui.png" style="width:100%;max-width:1100px"&gt;
 &lt;source src="https://robinsujob.github.io/media/magicvoice/magicvoice-demo.mp4" type="video/mp4"&gt;
 &lt;a href="https://robinsujob.github.io/media/magicvoice/magicvoice-demo.mp4"&gt;Download the MagicVoice demo video&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;If your browser does not support embedded playback, you can &lt;a class="link" href="https://robinsujob.github.io/media/magicvoice/magicvoice-demo.mp4" &gt;download the demo video directly&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;GPT-SoVITS lowered the barrier to few-shot voice cloning and cross-lingual speech synthesis. MagicVoice takes the next step by packaging these capabilities as a solution that can be rapidly deployed, easily used, and centrally managed within a customer&amp;rsquo;s AWS account.&lt;/p&gt;
&lt;p&gt;The value of MagicVoice lies not in any single model parameter, but in its end-to-end design for real-world usage:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Build a clean, intuitive frontend with AWS Cloudscape;&lt;/li&gt;
&lt;li&gt;Host and distribute the frontend through Amazon S3 and Amazon CloudFront;&lt;/li&gt;
&lt;li&gt;Run the GPT-SoVITS inference service on a GPU-enabled EC2 instance;&lt;/li&gt;
&lt;li&gt;Centrally manage characters, emotions, and model files in Amazon S3;&lt;/li&gt;
&lt;li&gt;Automate model synchronization and service reloads with Amazon EventBridge and AWS Systems Manager;&lt;/li&gt;
&lt;li&gt;Standardize repeatable deployment with AWS CDK and AWS CloudFormation;&lt;/li&gt;
&lt;li&gt;Separate model development from routine use to reduce complexity for end users.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Together, these design choices transform the developer-oriented GPT-SoVITS WebUI into an AWS TTS reference architecture that is easier to deploy, operate, and maintain.&lt;/p&gt;
&lt;h2 id="references"&gt;References
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://github.com/RVC-Boss/GPT-SoVITS" target="_blank" rel="noopener"
 &gt;GPT-SoVITS GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html" target="_blank" rel="noopener"
 &gt;Amazon CloudFront Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html" target="_blank" rel="noopener"
 &gt;Using Amazon S3 with Amazon EventBridge&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.aws.amazon.com/systems-manager/latest/userguide/run-command.html" target="_blank" rel="noopener"
 &gt;AWS Systems Manager Run Command&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.aws.amazon.com/cdk/v2/guide/home.html" target="_blank" rel="noopener"
 &gt;AWS CDK Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://calculator.aws/" target="_blank" rel="noopener"
 &gt;AWS Pricing Calculator&lt;/a&gt;&lt;/li&gt;
&lt;/ul&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><item><title>WordPress GenAI Plus - AI Content Generation Plugin</title><link>https://robinsujob.github.io/p/wordpress-genai-plus/</link><pubDate>Mon, 29 Apr 2024 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/wordpress-genai-plus/</guid><description>&lt;p&gt;Generative AI (GenAI) has risen rapidly since 2022, sweeping the globe and demonstrating enormous potential across multiple domains — text-to-image, text-to-text, image-to-image, and more. Models like Stable Diffusion and DALL-E can generate realistic images from natural-language descriptions, opening new possibilities for creative design and visual arts. Meanwhile, large language models such as Claude and GPT enable natural, fluent conversational interactions, empowering content creation and Q&amp;amp;A applications.&lt;/p&gt;
&lt;p&gt;WordPress is a widely used open-source content management system (CMS) ideal for creating and managing all types of websites — blogs, corporate sites, personal pages, and online stores. First released in 2003, it was designed to give users an easy-to-use platform for publishing content, even without a technical background.&lt;/p&gt;
&lt;p&gt;Now, leveraging the powerful AI capabilities of AWS, you can experience an intelligent AI writing assistant directly inside WordPress to accelerate your content creation. The newly launched WordPress GenAI Plus solution seamlessly integrates Claude 3 (via Amazon Bedrock) and Stable Diffusion into the WordPress editor. Simply provide a prompt or topic direction, and the AI will automatically generate article content and images. You can iterate as many times as needed until you achieve the ideal result.&lt;/p&gt;
&lt;p&gt;The main features provided by WordPress GenAI Plus writing assistant include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Text Generation&lt;/strong&gt;: Generate articles based on user prompts&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Image Generation&lt;/strong&gt;: Generate images based on user prompts&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Translation&lt;/strong&gt;: Currently supports Chinese, English, French, Japanese, and Korean as target languages; source language is unrestricted&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Grammar Check&lt;/strong&gt;: Provides grammar correction suggestions for selected English paragraphs (English only)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This solution supports one-click deployment via an Amazon CloudFormation template. By deploying the stack, users get the complete infrastructure — WordPress site, database, CDN, and AI capabilities — greatly simplifying setup and usage.&lt;/p&gt;
&lt;h2 id="architecture-overview"&gt;Architecture Overview
&lt;/h2&gt;&lt;p&gt;The WordPress GenAI Plus solution can be deployed in any AWS global region. It offers both a two-tier architecture (separating web and database layers) and a traditional LNMP (Linux, Nginx, MySQL, PHP) all-in-one architecture. The two-tier architecture is shown below:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Two-tier architecture" class="gallery-image" data-flex-basis="297px" data-flex-grow="124" height="2451" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img1.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img1_hu_ef986cc92121e38c.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img1_hu_1f38168aeec108de.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img1_hu_9cb7cba0cd6786a8.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img1.jpg 3042w" width="3042"&gt;&lt;/p&gt;
&lt;p&gt;Architecture highlights: Two-tier (web + data), WordPress on public subnet, RDS on private subnet, multi-AZ option, CloudFront CDN, Lambda + Bedrock integration for GenAI capabilities. EC2, RDS, and Lambda can be deployed in any region; Bedrock is available in us-east-1 or us-west-2.&lt;/p&gt;
&lt;h2 id="deployment-process"&gt;Deployment Process
&lt;/h2&gt;&lt;h3 id="model-access-preparation"&gt;Model Access Preparation
&lt;/h3&gt;&lt;p&gt;Before getting started, you need to request model access permissions in Amazon Bedrock.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select the Bedrock service in the AWS global console&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Select Bedrock service" class="gallery-image" data-flex-basis="423px" data-flex-grow="176" height="1632" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img2.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img2_hu_ff7adb1de6e28a7c.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img2_hu_ed60cc0f95369656.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img2_hu_eb0db7bf6f95213e.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img2.jpg 2880w" width="2880"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select the model deployment region (us-east-1 or us-west-2) in the top-right corner&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Select region" class="gallery-image" data-flex-basis="424px" data-flex-grow="176" height="1628" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img3.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img3_hu_c6dbf5acc69a53a.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img3_hu_690ac4e1519353c2.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img3_hu_7ffe6cbb83d97648.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img3.jpg 2880w" width="2880"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the left sidebar, select &amp;ldquo;Model access&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Model access" class="gallery-image" data-flex-basis="426px" data-flex-grow="177" height="1622" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img4.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img4_hu_eb5eae4fa56907c.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img4_hu_2084e03a8b9945a9.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img4_hu_8bbe8fe229be6d5f.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img4.jpg 2880w" width="2880"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click the &amp;ldquo;Manage model access&amp;rdquo; button&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Manage model access" class="gallery-image" data-flex-basis="602px" data-flex-grow="250" height="1148" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img5.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img5_hu_4c7e1fcce0773894.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img5_hu_914817e58e4a3a46.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img5_hu_9c6dc810c37010b5.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img5.jpg 2880w" width="2880"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Check the boxes for SDXL1.0, Claude 3 Sonnet, and Claude 3 Haiku, then click &amp;ldquo;Save changes&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Select models" class="gallery-image" data-flex-basis="462px" data-flex-grow="192" height="1368" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img6.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img6_hu_78eff3ca9133ee4f.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img6_hu_d3ad62343717f74c.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img6_hu_cc484afaeb398a9b.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img6.jpg 2634w" width="2634"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Wait for permission to be granted (status changes to &amp;ldquo;Access granted&amp;rdquo;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="create-key-pair"&gt;Create Key Pair
&lt;/h3&gt;&lt;p&gt;A key pair allows you to securely connect to your Amazon EC2 instance via SSH. Before deployment, make sure you have created a key pair.&lt;/p&gt;
&lt;p&gt;If you haven&amp;rsquo;t created one yet, &lt;a class="link" href="https://console.aws.amazon.com/ec2/home?#CreateKeyPair:" target="_blank" rel="noopener"
 &gt;click here to create a key pair&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Create key pair" class="gallery-image" data-flex-basis="421px" data-flex-grow="175" height="1617" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img7.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img7_hu_cad5c45fa3e0a90d.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img7_hu_f6cce1f57c16990f.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img7_hu_94281de5e7298609.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img7.jpg 2842w" width="2842"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Confirm the deployment region, enter a key pair name, click &amp;ldquo;Create key pair&amp;rdquo; and save it securely.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="create-cloudformation-stack"&gt;Create CloudFormation Stack
&lt;/h3&gt;&lt;p&gt;Click the link above to enter the stack deployment page.&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="https://console.aws.amazon.com/cloudformation/home?#stacks/create/template?templateURL=https://aws-cn-getting-started.s3.us-west-2.amazonaws.com/wordpress-plus/WordpressTwoLayer.template.json" target="_blank" rel="noopener"
 &gt;Click to deploy&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Confirm the deployment region in the top-right corner (must match your key pair region), then specify the following parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Custom stack name&lt;/li&gt;
&lt;li&gt;EC2 instance type&lt;/li&gt;
&lt;li&gt;EC2 disk size&lt;/li&gt;
&lt;li&gt;EC2 key pair&lt;/li&gt;
&lt;li&gt;Database username&lt;/li&gt;
&lt;li&gt;Database password (min 8 chars, no /, quotes, or @)&lt;/li&gt;
&lt;li&gt;Database instance type&lt;/li&gt;
&lt;li&gt;Database storage size&lt;/li&gt;
&lt;li&gt;Multi-AZ deployment option&lt;/li&gt;
&lt;li&gt;Bedrock deployment region&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Click Next.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Parameter configuration 1" class="gallery-image" data-flex-basis="437px" data-flex-grow="182" height="1482" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img8.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img8_hu_7d2b2c9cef5c41c6.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img8_hu_421e9f77cd018aa8.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img8_hu_439213e3bdf1cd13.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img8.jpg 2701w" width="2701"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Parameter configuration 2" class="gallery-image" data-flex-basis="340px" data-flex-grow="141" height="1481" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img9.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img9_hu_6288bdd7fec4c900.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img9_hu_b4fcc6939852e6fa.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img9.jpg 2103w" width="2103"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On step 3 &amp;ldquo;Configure stack options&amp;rdquo;, click Next&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Configure stack options" class="gallery-image" data-flex-basis="468px" data-flex-grow="195" height="1267" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img10.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img10_hu_95518abbf47e5ca7.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img10_hu_fb67f51952fa9f00.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img10_hu_2115bc5a21c35a03.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img10.jpg 2471w" width="2471"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On step 4, check the IAM acknowledgments and CAPABILITY_AUTO_EXPAND, then click Submit&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Confirm and submit" class="gallery-image" data-flex-basis="1388px" data-flex-grow="578" height="334" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img11.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img11_hu_3d90c68d964ed45.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img11_hu_ff83e94cfa74f7ac.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img11.jpg 1933w" width="1933"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Wait about 10 minutes for the stack status to become CREATE_COMPLETE&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Creating" class="gallery-image" data-flex-basis="286px" data-flex-grow="119" height="946" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img12.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img12_hu_81f94874089ae4dd.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img12.jpg 1129w" width="1129"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Creation complete" class="gallery-image" data-flex-basis="1107px" data-flex-grow="461" height="273" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img13.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img13_hu_3781969cab94306a.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img13.jpg 1260w" width="1260"&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Check the Outputs tab for GenAI Function URL, WordPress install URL, admin URL, and site URL&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Outputs" class="gallery-image" data-flex-basis="496px" data-flex-grow="206" height="537" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img14.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img14_hu_353ab9d564899a99.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img14.jpg 1111w" width="1111"&gt;&lt;/p&gt;
&lt;h2 id="start-using-wordpress-ai-capabilities"&gt;Start Using WordPress AI Capabilities
&lt;/h2&gt;&lt;h3 id="initialize-wordpress"&gt;Initialize WordPress
&lt;/h3&gt;&lt;p&gt;After deployment, find the InstallWordPress field in the CloudFormation stack outputs and open the URL to configure WordPress.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Install WordPress" class="gallery-image" data-flex-basis="746px" data-flex-grow="310" height="926" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img15.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img15_hu_bf06d4c5c6828201.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img15_hu_481036577f33f7d8.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img15_hu_2d7b049f3e10d176.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img15.jpg 2879w" width="2879"&gt;&lt;/p&gt;
&lt;p&gt;In the one-click deployment, database information is pre-configured. You only need to set up your site title, username, and password, then click &amp;ldquo;Install WordPress&amp;rdquo; and log into the admin panel.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Configure site info" class="gallery-image" data-flex-basis="223px" data-flex-grow="93" height="1758" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img16.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img16_hu_86e385ae7faafc9c.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img16_hu_641f58c03ebd0476.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img16.jpg 1639w" width="1639"&gt;&lt;/p&gt;
&lt;h3 id="enable-the-genai-plugin"&gt;Enable the GenAI Plugin
&lt;/h3&gt;&lt;p&gt;In the WordPress admin panel, click &amp;ldquo;Plugins&amp;rdquo;, find &amp;ldquo;Amazon AI writing assistant&amp;rdquo; and click Activate.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Enable plugin" class="gallery-image" data-flex-basis="400px" data-flex-grow="166" height="1083" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img17.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img17_hu_efdbd2773c46eb06.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img17_hu_e62b2ca4d64d37f7.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img17.jpg 1805w" width="1805"&gt;&lt;/p&gt;
&lt;p&gt;The Lambda URL and Region are pre-configured. Verify and click Save.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Plugin configuration" class="gallery-image" data-flex-basis="456px" data-flex-grow="190" height="1388" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img18.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img18_hu_56798583b4336e7f.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img18_hu_a787804102fa7bcf.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img18_hu_f4020940aeba884f.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img18.jpg 2641w" width="2641"&gt;&lt;/p&gt;
&lt;h3 id="experience-genai-capabilities"&gt;Experience GenAI Capabilities
&lt;/h3&gt;&lt;p&gt;In the WordPress admin, click &amp;ldquo;New → Post&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="New post" class="gallery-image" data-flex-basis="457px" data-flex-grow="190" height="586" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img19.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img19_hu_824c0100d2ea8ab7.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img19.jpg 1118w" width="1118"&gt;&lt;/p&gt;
&lt;p&gt;In the editor body, type &lt;code&gt;/ask&lt;/code&gt; to trigger the Ask AI plugin. Click it to start using the AI features.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Ask AI plugin" class="gallery-image" data-flex-basis="658px" data-flex-grow="274" height="426" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img20.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img20_hu_71405a2822eef0f3.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img20.jpg 1168w" width="1168"&gt;&lt;/p&gt;
&lt;p&gt;You can enter text-to-text or text-to-image prompts in Chinese or English in the popup input box.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Text generation example" class="gallery-image" data-flex-basis="766px" data-flex-grow="319" height="432" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img21.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img21_hu_e2be7a30c6459c1b.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img21.jpg 1380w" width="1380"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Image generation example" class="gallery-image" data-flex-basis="778px" data-flex-grow="324" height="401" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img22.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img22_hu_21aebfa7b3e7210c.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img22.jpg 1300w" width="1300"&gt;&lt;/p&gt;
&lt;p&gt;See the demo below:&lt;/p&gt;
&lt;p&gt;&lt;img alt="GenAI demo" class="gallery-image" data-flex-basis="368px" data-flex-grow="153" height="521" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/gif1.gif" width="800"&gt;&lt;/p&gt;
&lt;p&gt;The GenAI plugin also supports translation and grammar checking:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Translation&lt;/strong&gt;: Enter text in any language, click the pen icon in the floating toolbar → Translate Text. Target language is set in the plugin configuration page. Supported: ZH_CN, EN_US, FR, JA, KO.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Translation demo" class="gallery-image" data-flex-basis="417px" data-flex-grow="173" height="345" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/gif2.gif" width="600"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Translation config" class="gallery-image" data-flex-basis="428px" data-flex-grow="178" height="1400" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img25.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img25_hu_6826f283d45e92c0.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img25_hu_c1733b4c18dafc5e.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img25_hu_6e5b049473cfecbd.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img25.jpg 2500w" width="2500"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Grammar Check&lt;/strong&gt;: For text you want to correct, click the pen icon in the floating toolbar → Correct Text.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Grammar check demo" class="gallery-image" data-flex-basis="417px" data-flex-grow="173" height="345" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/gif3.gif" width="600"&gt;&lt;/p&gt;
&lt;h2 id="alternative-architecture"&gt;Alternative Architecture
&lt;/h2&gt;&lt;p&gt;You can configure your own domain name in Amazon CloudFront, use Certificate Manager to request a free public certificate for HTTPS, and update the site address in the WordPress admin panel.&lt;/p&gt;
&lt;p&gt;This solution also supports a traditional LNMP all-in-one WordPress architecture:&lt;/p&gt;
&lt;p&gt;&lt;img alt="LNMP architecture" class="gallery-image" data-flex-basis="709px" data-flex-grow="295" height="1259" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/wordpress-genai-plus/images/img27.jpg" srcset="https://robinsujob.github.io/p/wordpress-genai-plus/images/img27_hu_1a9e40034b81b345.jpg 800w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img27_hu_959d415c4d7de88c.jpg 1600w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img27_hu_b44b6ce634ac4395.jpg 2400w, https://robinsujob.github.io/p/wordpress-genai-plus/images/img27.jpg 3721w" width="3721"&gt;&lt;/p&gt;
&lt;p&gt;Deploy the LNMP architecture: &lt;a class="link" href="https://console.aws.amazon.com/cloudformation/home?#stacks/create/template?templateURL=https://aws-cn-getting-started.s3.us-west-2.amazonaws.com/wordpress-plus/WordpressInOne.template.json" target="_blank" rel="noopener"
 &gt;Click to deploy&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary
&lt;/h2&gt;&lt;p&gt;Through this tutorial, you can deploy WordPress GenAI Plus on AWS with one click, integrating the power of generative AI into the WordPress editor for a brand-new AI-powered content creation experience.&lt;/p&gt;
&lt;p&gt;Related Resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://aws.amazon.com/cn/campaigns/aigc" target="_blank" rel="noopener"
 &gt;AWS AIGC&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/wordpress-genai-plus-accelerate-your-website-content-creation-with-generative-ai/" target="_blank" rel="noopener"
 &gt;WordPress GenAI Plus: Accelerate Your Website Content Creation with Generative AI&lt;/a&gt;&lt;/p&gt;

 &lt;/blockquote&gt;</description></item><item><title>China CloudFront SSL Plugin Deployment Guide</title><link>https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/</link><pubDate>Wed, 15 Nov 2023 00:00:00 +0800</pubDate><guid>https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/</guid><description>&lt;img src="https://robinsujob.github.io/" alt="Featured image of post China CloudFront SSL Plugin Deployment Guide" /&gt;&lt;p&gt;This article applies to AWS China Region services. You will learn how to use Amazon CloudFront in the China Region to accelerate and distribute traffic from websites deployed on EC2, and use the &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&lt;/a&gt; to deploy free SSL certificates to protect your site. The plugin helps you generate, renew, and download free SSL certificates in the AWS China Regions, with Amazon CloudFront integration and automatic certificate renewal. You can also refer to the EC2-CloudFront integration section for configuring CloudFront to distribute EC2 website traffic in AWS Global Regions.&lt;/p&gt;
&lt;h2 id="why-choose-amazon-cloudfront"&gt;Why Choose Amazon CloudFront?
&lt;/h2&gt;&lt;p&gt;Amazon CloudFront is a Content Delivery Network (CDN) service provided by AWS. Using a CDN reduces website load times, lowers bounce rates, and increases traffic and revenue, while also reducing the load on origin servers, improving website stability, security, availability, and reliability. Amazon CloudFront securely delivers data, videos, applications, and APIs to customers globally with low latency and high transfer speeds in a developer-friendly environment, and integrates seamlessly with Amazon S3, Elastic Load Balancer, Amazon EC2, and more.&lt;/p&gt;
&lt;p&gt;Amazon CloudFront not only accelerates your website and reduces origin server load, but also lowers the data transfer costs for traffic leaving your AWS-hosted website to the internet. For example, compared to EC2&amp;rsquo;s outbound data transfer costs, using Amazon CloudFront in the AWS China Regions can help you reduce outbound data transfer costs by at least 67%. For specific pricing, refer to the AWS China Region official website &lt;a class="link" href="https://www.amazonaws.cn/ec2/pricing/#Amazon_EC2_.E6.95.B0.E6.8D.AE.E4.BC.A0.E8.BE.93" target="_blank" rel="noopener"
 &gt;EC2 Data Transfer Pricing&lt;/a&gt; and &lt;a class="link" href="https://www.amazonaws.cn/cloudfront/pricing/#On-demand_Pricing" target="_blank" rel="noopener"
 &gt;CloudFront Data Transfer Pricing&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="considerations-for-using-cloudfront-in-china-regions"&gt;Considerations for Using CloudFront in China Regions
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ICP Filing and Domain Registration:&lt;/strong&gt; According to relevant laws and regulations, if you need to host a website in mainland China, you must first complete ICP filing. Domains without ICP filing cannot serve web content. Please prepare an ICP-filed domain. Refer to the AWS China &lt;a class="link" href="https://www.amazonaws.cn/support/icp/" target="_blank" rel="noopener"
 &gt;ICP Filing Support Documentation&lt;/a&gt; for more details on obtaining the required ICP filing for your domain.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CloudFront Provided Domain:&lt;/strong&gt; CloudFront automatically assigns a &lt;code&gt;*.cloudfront.cn&lt;/code&gt; domain. However, due to ICP filing requirements, you cannot directly use this domain for website services in China. You must add an ICP-filed domain as an alternate domain name (also known as CNAME) to your CloudFront distribution, and then use the alternate domain name to access your website.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CloudFront SSL/TLS Certificate Integration:&lt;/strong&gt; Amazon CloudFront in the China Regions does not currently support &lt;a class="link" href="https://www.amazonaws.cn/certificate-manager/features/" target="_blank" rel="noopener"
 &gt;Amazon Certificate Manager&lt;/a&gt;. If you need to use SSL/TLS certificates with CloudFront, you can obtain them from third-party certificate authorities and &lt;a class="link" href="https://docs.amazonaws.cn/AmazonCloudFront/latest/DeveloperGuide/cnames-and-https-procedures.html#cnames-and-https-uploading-certificates" target="_blank" rel="noopener"
 &gt;import SSL/TLS certificates&lt;/a&gt;. You can also use the &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&lt;/a&gt; to obtain free SSL/TLS certificates, which will be covered in detail in the &amp;ldquo;Deploy Free Certificates with China CloudFront SSL Plugin&amp;rdquo; section of this article.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Feature Differences Between China and Global Regions:&lt;/strong&gt; Amazon CloudFront in the China Regions does not currently support Lambda@Edge, Amazon WAF, and other features. See the &lt;a class="link" href="https://docs.amazonaws.cn/aws/latest/userguide/cloudfront.html#feature-diff" target="_blank" rel="noopener"
 &gt;documentation&lt;/a&gt; for more details.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites
&lt;/h2&gt;&lt;p&gt;To complete all sections of this article and get a consistent experience with AWS services, please ensure you meet the following prerequisites.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Your AWS China Region account has completed ICP filing, with ports 80/443 open&lt;/li&gt;
&lt;li&gt;You have an ICP-filed domain&lt;/li&gt;
&lt;li&gt;Use &lt;a class="link" href="https://www.amazonaws.cn/route53/" target="_blank" rel="noopener"
 &gt;Amazon Route 53&lt;/a&gt; as your DNS service. If you haven&amp;rsquo;t migrated your DNS to Amazon Route 53 yet, see the &lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/migrate-domain-to-amazon-route53/" target="_blank" rel="noopener"
 &gt;reference documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="integrating-ec2-with-cloudfront"&gt;Integrating EC2 with CloudFront
&lt;/h2&gt;&lt;p&gt;In the following sections, you will launch an EC2 instance, set up a web server, integrate EC2 with CloudFront, and deploy a free SSL certificate using the China CloudFront SSL Plugin.&lt;/p&gt;
&lt;p&gt;You will also learn some tips for using EC2 and CloudFront, such as using Elastic IP to fix your EC2 public DNS hostname for CloudFront origins, or using AWS-managed prefix lists to enhance EC2 security.&lt;/p&gt;
&lt;p&gt;The deployment architecture is shown below:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Deployment Architecture" class="gallery-image" data-flex-basis="279px" data-flex-grow="116" height="1090" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/architecture.png" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/architecture_hu_7853b82d2810f37e.png 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/architecture.png 1268w" width="1268"&gt;&lt;/p&gt;
&lt;h3 id="create-ec2-and-install-web-server"&gt;Create EC2 and Install Web Server
&lt;/h3&gt;&lt;p&gt;In this section, you will create an EC2 instance with a web server, then bind an Elastic IP to fix the EC2 public DNS hostname.&lt;/p&gt;
&lt;h4 id="1-launch-ec2-instance"&gt;1. Launch EC2 Instance
&lt;/h4&gt;&lt;p&gt;You can launch an EC2 instance from the EC2 console.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Launch EC2 Instance" class="gallery-image" data-flex-basis="398px" data-flex-grow="166" height="1183" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/ec2-create.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/ec2-create_hu_4bad2cd2999e9a49.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/ec2-create_hu_524d8415a1264fef.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/ec2-create.jpg 1965w" width="1965"&gt;&lt;/p&gt;
&lt;p&gt;Name your instance, e.g., &amp;ldquo;web-server&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;You can keep the default AMI and instance type.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AMI: Amazon Linux 2023&lt;/li&gt;
&lt;li&gt;Instance type: micro&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="AMI and Instance Type" class="gallery-image" data-flex-basis="398px" data-flex-grow="166" height="1183" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-2.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-2_hu_4bad2cd2999e9a49.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-2_hu_524d8415a1264fef.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-2.jpg 1965w" width="1965"&gt;&lt;/p&gt;
&lt;p&gt;Under &amp;ldquo;Key pair&amp;rdquo;, select an existing key pair or create a new one for subsequent system administration.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Key Pair Settings" class="gallery-image" data-flex-basis="639px" data-flex-grow="266" height="651" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-3.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-3_hu_9f6ea6be1004f543.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-3_hu_cd1424e493dd60e4.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-3.jpg 1734w" width="1734"&gt;&lt;/p&gt;
&lt;p&gt;For network settings, ensure your EC2 instance is deployed in a public subnet, and check &amp;ldquo;Allow HTTP traffic from the internet&amp;rdquo; to make port 80 accessible from the internet.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Network Configuration" class="gallery-image" data-flex-basis="260px" data-flex-grow="108" height="1532" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-4.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-4_hu_6eb00b634c3b6715.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-4_hu_daaf7b7b2d61cf19.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-4.jpg 1663w" width="1663"&gt;&lt;/p&gt;
&lt;p&gt;Expand the &amp;ldquo;Advanced details&amp;rdquo; section at the bottom:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Advanced Details" class="gallery-image" data-flex-basis="592px" data-flex-grow="246" height="622" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-5.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-5_hu_b78cc41ef9237432.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-5.jpg 1536w" width="1536"&gt;&lt;/p&gt;
&lt;p&gt;At the bottom of the page under &amp;ldquo;User data&amp;rdquo;, paste the following script to install a web server on first boot. Then click &amp;ldquo;Launch instance&amp;rdquo; to start the instance.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;yum install -y httpd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; httpd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;systemctl start httpd
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;img alt="User Data" class="gallery-image" data-flex-basis="274px" data-flex-grow="114" height="1378" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-6.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-6_hu_7ced7558e6bc727.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-6.jpg 1576w" width="1576"&gt;&lt;/p&gt;
&lt;h4 id="2-create-elastic-ip-and-associate-with-ec2"&gt;2. Create Elastic IP and Associate with EC2
&lt;/h4&gt;&lt;p&gt;&lt;a class="link" href="https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html" target="_blank" rel="noopener"
 &gt;Elastic IP&lt;/a&gt; is a static IPv4 address designed for cloud computing. Using an Elastic IP ensures your EC2 instance&amp;rsquo;s public IP address and public DNS hostname remain unchanged. In this section, you will learn how to associate an Elastic IP with your EC2 instance and access your site using the EC2 instance&amp;rsquo;s public DNS hostname.&lt;/p&gt;
&lt;p&gt;Find Elastic IP under &amp;ldquo;Network &amp;amp; Security&amp;rdquo; in the EC2 console left menu.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Elastic IP Menu" class="gallery-image" data-flex-basis="1917px" data-flex-grow="799" height="201" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-7.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-7_hu_dcee5b048214ea12.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-7_hu_a09c30cd09c9bc23.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-7.jpg 1606w" width="1606"&gt;&lt;/p&gt;
&lt;p&gt;Click &amp;ldquo;Allocate Elastic IP address&amp;rdquo; in the upper right, then click &amp;ldquo;Allocate&amp;rdquo; to obtain an Elastic IP.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Allocate Elastic IP" class="gallery-image" data-flex-basis="542px" data-flex-grow="226" height="1058" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-8.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-8_hu_ef1e899f2d63465d.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-8_hu_77727674391f39a8.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-8.jpg 2392w" width="2392"&gt;&lt;/p&gt;
&lt;p&gt;Select your Elastic IP, click the &amp;ldquo;Actions&amp;rdquo; button in the upper right, and choose &amp;ldquo;Associate Elastic IP address&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Associate Elastic IP" class="gallery-image" data-flex-basis="423px" data-flex-grow="176" height="1375" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-9.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-9_hu_c73c28e244703e66.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-9_hu_db6574310cf99be4.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-9_hu_152a186740569800.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-9.jpg 2426w" width="2426"&gt;&lt;/p&gt;
&lt;p&gt;Select your previously created EC2 instance and click &amp;ldquo;Associate&amp;rdquo; to ensure the EC2 instance&amp;rsquo;s public IP address remains stable.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Select EC2 Instance" class="gallery-image" data-flex-basis="338px" data-flex-grow="141" height="1256" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-10.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-10_hu_bf400582c310b418.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-10_hu_d5b93b8eec98cf94.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-10.jpg 1772w" width="1772"&gt;&lt;/p&gt;
&lt;p&gt;Click the &amp;ldquo;Instances&amp;rdquo; menu on the left to return to the instance list, select your instance, and copy the public IPv4 DNS.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Copy Public DNS" class="gallery-image" data-flex-basis="856px" data-flex-grow="356" height="782" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-11.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-11_hu_e13e176090677f6.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-11_hu_2eacf8c682b2ccda.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-11_hu_1b2b525001061f85.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-11.jpg 2791w" width="2791"&gt;&lt;/p&gt;
&lt;p&gt;Access the public DNS hostname in your browser to verify the web server is installed. You can see the site is currently using port 80 without an SSL/TLS certificate.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Browser Verification" class="gallery-image" data-flex-basis="274px" data-flex-grow="114" height="1485" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-12.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-12_hu_4b723108790f6ed8.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-12_hu_da4cc718ccb5b425.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-12.jpg 1699w" width="1699"&gt;&lt;/p&gt;
&lt;p&gt;In the following sections, you will use this hostname as the CloudFront origin to divert website traffic from EC2 to Amazon CloudFront.&lt;/p&gt;
&lt;h3 id="create-cloudfront-distribution"&gt;Create CloudFront Distribution
&lt;/h3&gt;&lt;p&gt;In this section, you will create a CloudFront distribution and associate it with the previously deployed EC2 instance, routing traffic through CloudFront to accelerate content delivery.&lt;/p&gt;
&lt;h4 id="1-create-cloudfront-distribution-and-associate-ec2"&gt;1. Create CloudFront Distribution and Associate EC2
&lt;/h4&gt;&lt;p&gt;Next, you will quickly set up a CloudFront distribution. Go to the CloudFront console and create a distribution:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Create CloudFront Distribution" class="gallery-image" data-flex-basis="606px" data-flex-grow="252" height="1325" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-13.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-13_hu_a8367bef1aae0926.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-13_hu_4d508bb4a235ad8d.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-13_hu_5453637f6d5fbdeb.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-13.jpg 3351w" width="3351"&gt;&lt;/p&gt;
&lt;p&gt;On the CloudFront configuration page, you will see the basic configuration elements that a CloudFront distribution requires:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Origin&lt;/strong&gt; – The origin server, supporting multiple AWS services including but not limited to S3, EC2, ELB, API Gateway, as well as third-party origins&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache Behavior&lt;/strong&gt; – Define caching behavior through path matching, enable transfer compression, allowed request methods, access control, etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Settings&lt;/strong&gt; – Alternate domain names (CNAME), SSL certificate, default root object, logging, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the origin, use the EC2 public DNS (with Elastic IP) as the origin domain. Ensure the origin protocol is HTTP.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Origin Settings" class="gallery-image" data-flex-basis="414px" data-flex-grow="172" height="978" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-14.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-14_hu_c12930d6d67ea46.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-14_hu_8583eeaa9f5891e9.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-14.jpg 1690w" width="1690"&gt;&lt;/p&gt;
&lt;p&gt;For the default cache behavior, you can keep the default settings:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Cache Behavior Settings" class="gallery-image" data-flex-basis="711px" data-flex-grow="296" height="909" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-15.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-15_hu_12c7444888d92324.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-15_hu_65ebbbf0958e115e.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-15_hu_20aef0f435f57651.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-15.jpg 2694w" width="2694"&gt;&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Due to compliance requirements, the default CloudFront distribution domain in the Beijing/Ningxia regions cannot be accessed directly. You must complete domain ICP filing and set up CNAME DNS resolution before access is possible.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;p&gt;In the settings section, enter your ICP-filed domain as the alternate domain name (CNAME):&lt;/p&gt;
&lt;p&gt;&lt;img alt="Alternate Domain Name Settings" class="gallery-image" data-flex-basis="286px" data-flex-grow="119" height="1438" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-16.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-16_hu_14196fd7b272dfcd.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-16_hu_94de9764e2460cf6.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-16.jpg 1716w" width="1716"&gt;&lt;/p&gt;
&lt;p&gt;After creation, wait for deployment to complete. Once deployed, check your alternate domain name — if the domain has passed ICP filing, you should see a &amp;ldquo;green checkmark&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="ICP Filing Green Checkmark" class="gallery-image" data-flex-basis="153px" data-flex-grow="63" height="1698" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-17.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-17_hu_acad7026d9b16373.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-17.jpg 1086w" width="1086"&gt;&lt;/p&gt;
&lt;p&gt;After deployment, go to Route 53 (or your DNS provider) to update the DNS configuration. Using Route 53 as an example, enter the corresponding domain&amp;rsquo;s hosted zone and create a new record.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Route 53 Create Record" class="gallery-image" data-flex-basis="405px" data-flex-grow="168" height="956" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-18.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-18_hu_970077f08855e81d.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-18_hu_995f1b9e1c60399.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-18.jpg 1615w" width="1615"&gt;&lt;/p&gt;
&lt;p&gt;Fill in the DNS record:&lt;/p&gt;
&lt;p&gt;&lt;img alt="DNS Record Configuration" class="gallery-image" data-flex-basis="693px" data-flex-grow="289" height="1085" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-19.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-19_hu_b37ebdfd46e25cb.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-19_hu_490015ade77f4a67.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-19_hu_d75cfeda12c8ce18.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-19.jpg 3136w" width="3136"&gt;&lt;/p&gt;
&lt;p&gt;After completing the DNS update, open your browser and access the ICP-filed domain:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Browser Access Domain" class="gallery-image" data-flex-basis="539px" data-flex-grow="224" height="1010" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-20.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-20_hu_36b565ec92948586.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-20_hu_58b3a2674e642329.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-20.jpg 2270w" width="2270"&gt;&lt;/p&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you encounter a 502 error, check whether EC2 has an SSL certificate installed or whether the origin port is correct. See the &lt;a class="link" href="https://docs.amazonaws.cn/AmazonCloudFront/latest/DeveloperGuide/http-502-bad-gateway.html" target="_blank" rel="noopener"
 &gt;documentation&lt;/a&gt;. If you encounter a 403 error, ensure you are accessing via the ICP-filed domain.&lt;/p&gt;

 &lt;/blockquote&gt;
&lt;h4 id="2-enhance-ec2-and-website-security"&gt;2. Enhance EC2 and Website Security
&lt;/h4&gt;&lt;p&gt;In this section, you will use &lt;a class="link" href="https://docs.amazonaws.cn/vpc/latest/userguide/working-with-aws-managed-prefix-lists.html#available-aws-managed-prefix-lists" target="_blank" rel="noopener"
 &gt;AWS-managed prefix lists&lt;/a&gt; to enhance EC2 security. You can use the Amazon CloudFront managed prefix list to restrict inbound HTTP/HTTPS traffic to only the IP addresses of CloudFront origin-facing servers.&lt;/p&gt;
&lt;p&gt;Select your instance, go to the EC2 security group, and edit the inbound rules: add an HTTP rule, enter &amp;ldquo;cloudfront&amp;rdquo; in the source field, select the &lt;code&gt;com.amazonaws.global.cloudfront.origin-facing&lt;/code&gt; prefix list, and remove the existing &lt;code&gt;0.0.0.0/0&lt;/code&gt; rule.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Security Group Prefix List Configuration" class="gallery-image" data-flex-basis="382px" data-flex-grow="159" height="1065" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-21.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-21_hu_f948369aa9eb93d9.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-21_hu_aa508796cb61f82d.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-21.jpg 1696w" width="1696"&gt;&lt;/p&gt;
&lt;p&gt;You can also associate SSL/TLS certificates with CloudFront to enhance website security. In the following section, you will deploy free SSL certificates using the China CloudFront SSL Plugin.&lt;/p&gt;
&lt;h2 id="deploy-free-certificates-with-china-cloudfront-ssl-plugin"&gt;Deploy Free Certificates with China CloudFront SSL Plugin
&lt;/h2&gt;&lt;p&gt;Before starting, please confirm once again that you are using Amazon Route 53 for DNS resolution. This section covers the deployment process only. For more details, see the &lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/create-ssl-with-cloudfront/?nc1=h_ls" target="_blank" rel="noopener"
 &gt;China CloudFront SSL Plugin&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="1-initialize-deployment"&gt;1. Initialize Deployment
&lt;/h3&gt;&lt;p&gt;Deploy via CloudFormation. Click the &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/ChinaCloudFrontSslPluginStack.json" target="_blank" rel="noopener"
 &gt;link&lt;/a&gt; to launch the stack in the CloudFormation console.&lt;/p&gt;
&lt;p&gt;&lt;img alt="CloudFormation Deployment" class="gallery-image" data-flex-basis="381px" data-flex-grow="158" height="898" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-22.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-22_hu_c48fc7de493a412d.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-22.jpg 1426w" width="1426"&gt;&lt;/p&gt;
&lt;h3 id="2-enter-deployment-parameters"&gt;2. Enter Deployment Parameters
&lt;/h3&gt;&lt;p&gt;Specify stack details with the following parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stack Name:&lt;/strong&gt; Name your stack&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Email:&lt;/strong&gt; Enter your email for SNS email notifications (only one email supported)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Domain Name:&lt;/strong&gt; Enter the domain names for the SSL certificate. Supports wildcard domains and multiple domains (comma-separated)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SSL Renew Interval Days:&lt;/strong&gt; Enter the certificate renewal interval. Let&amp;rsquo;s Encrypt certificates are valid for 90 days; enter a number between 1 and 89. Recommended default: 80 days.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Stack Parameters" class="gallery-image" data-flex-basis="547px" data-flex-grow="228" height="1408" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-23.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-23_hu_df0d35d2e1320a42.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-23_hu_fb9028b1c9581b35.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-23_hu_98d013332fd98823.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-23.jpg 3211w" width="3211"&gt;&lt;/p&gt;
&lt;h3 id="3-confirm-deployment"&gt;3. Confirm Deployment
&lt;/h3&gt;&lt;p&gt;Review the deployment details on the current page, check the &amp;ldquo;I acknowledge&amp;rdquo; box at the bottom, and click &lt;strong&gt;Submit&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Confirm Deployment" class="gallery-image" data-flex-basis="540px" data-flex-grow="225" height="1500" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-24.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-24_hu_97040fb6988a5f8.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-24_hu_3530ff7150daad0c.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-24_hu_8c5bc23ad109306f.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-24.jpg 3378w" width="3378"&gt;&lt;/p&gt;
&lt;p&gt;After submission, you will see resources being created in the stack events tab. Wait approximately 3 minutes.&lt;/p&gt;
&lt;h3 id="4-subscribe-to-sns-notifications-promptly"&gt;4. Subscribe to SNS Notifications Promptly
&lt;/h3&gt;&lt;p&gt;During the stack deployment process, check your email promptly. You will receive an SNS subscription confirmation request from &lt;a class="link" href="mailto:no-reply@sns.amazonaws.com" &gt;no-reply@sns.amazonaws.com&lt;/a&gt;. Please click the confirmation link as soon as possible.&lt;/p&gt;
&lt;p&gt;&lt;img alt="SNS Subscription Email" class="gallery-image" data-flex-basis="753px" data-flex-grow="313" height="1579" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-25.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-25_hu_cdde9165045830e8.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-25_hu_bb88619825b58bb2.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-25_hu_f203472c7d3c1c50.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-25.jpg 4956w" width="4956"&gt;&lt;/p&gt;
&lt;p&gt;Successful subscription confirmation:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Subscription Successful" class="gallery-image" data-flex-basis="1331px" data-flex-grow="554" height="566" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-26.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-26_hu_745d769f4f147290.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-26_hu_af2c5877f6070985.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-26_hu_2b7bfecfa67898b.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-26.jpg 3140w" width="3140"&gt;&lt;/p&gt;
&lt;h3 id="5-check-stack-deployment-progress"&gt;5. Check Stack Deployment Progress
&lt;/h3&gt;&lt;p&gt;When the stack status changes to green &lt;code&gt;CREATE_COMPLETE&lt;/code&gt;, the deployment is finished.&lt;/p&gt;
&lt;p&gt;Check the &amp;ldquo;Outputs&amp;rdquo; tab for quick links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CloudfrontConsole:&lt;/strong&gt; Access the CloudFront console to quickly bind the issued certificate&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ManagementWebURL:&lt;/strong&gt; Access SwaggerUI to view or delete existing SSL certificates in IAM&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;S3BucketURL:&lt;/strong&gt; Access the S3 console to download the issued SSL certificates&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Stack Outputs" class="gallery-image" data-flex-basis="1089px" data-flex-grow="453" height="526" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-27.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-27_hu_e4a40fc578f3a1ff.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-27_hu_d7c6996c56f5d4b4.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-27.jpg 2387w" width="2387"&gt;&lt;/p&gt;
&lt;h3 id="6-bind-ssl-certificate-in-the-amazon-cloudfront-console"&gt;6. Bind SSL Certificate in the Amazon CloudFront Console
&lt;/h3&gt;&lt;p&gt;After stack deployment is complete, an SSL certificate will be automatically requested for your domain. If you have subscribed to the SNS topic, you will receive an email notification confirming the certificate has been issued. The certificate name consists of the stack name and expiry time, e.g., &lt;code&gt;Certbot-2023-11-14-1540&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="SSL Certificate Email Notification" class="gallery-image" data-flex-basis="532px" data-flex-grow="221" height="542" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-28.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-28_hu_eea6111e60dfb38a.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-28.jpg 1202w" width="1202"&gt;&lt;/p&gt;
&lt;p&gt;Open the CloudFront console, select your distribution, and find the option to edit alternate domain names and SSL certificate.&lt;/p&gt;
&lt;p&gt;&lt;img alt="CloudFront Edit Settings" class="gallery-image" data-flex-basis="551px" data-flex-grow="229" height="1403" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-29.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-29_hu_9832edb84636551.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-29_hu_e1912aa46e2c65d8.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-29_hu_ab611836b6a34937.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-29.jpg 3222w" width="3222"&gt;&lt;/p&gt;
&lt;p&gt;Select the corresponding SSL certificate from the custom SSL certificate dropdown, then save changes.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Select SSL Certificate" class="gallery-image" data-flex-basis="444px" data-flex-grow="185" height="1743" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-30.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-30_hu_5dae4bd224493381.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-30_hu_26ea4d3b5146beb3.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-30_hu_4517dfc367337036.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-30.jpg 3226w" width="3226"&gt;&lt;/p&gt;
&lt;p&gt;After deployment, you can access your CloudFront-accelerated site via HTTPS in the browser and verify the SSL certificate issued by Let&amp;rsquo;s Encrypt, valid for 90 days.&lt;/p&gt;
&lt;p&gt;&lt;img alt="HTTPS Access Verification" class="gallery-image" data-flex-basis="437px" data-flex-grow="182" height="1492" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-31.jpg" srcset="https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-31_hu_1eee86b177ad311b.jpg 800w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-31_hu_3c5134eb5ca760eb.jpg 1600w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-31_hu_532535a6568d9bb.jpg 2400w, https://robinsujob.github.io/p/cloudfront-ssl-plugin-deployment-guide/images/cloudfront-ssl-31.jpg 2720w" width="2720"&gt;&lt;/p&gt;
&lt;p&gt;For more information on using the China CloudFront SSL Plugin, see the &lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/create-ssl-with-cloudfront/?nc1=h_ls" target="_blank" rel="noopener"
 &gt;plugin documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary
&lt;/h2&gt;&lt;p&gt;Through this article, you have learned the basics of Amazon CloudFront and how to divert website traffic deployed on EC2 to CloudFront for acceleration and cost savings. You have also learned to use AWS-managed prefix lists in EC2 security groups to ensure your EC2 only accepts traffic originating from CloudFront, and to deploy free SSL certificates using the China CloudFront SSL Plugin to protect your site with HTTPS.&lt;/p&gt;
&lt;h2 id="references"&gt;References
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://www.amazonaws.cn/getting-started/tutorials/create-ssl-with-cloudfront/?nc1=h_ls" target="_blank" rel="noopener"
 &gt;China CloudFront SSL Plugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://docs.amazonaws.cn/AmazonCloudFront/latest/DeveloperGuide/Introduction.html" target="_blank" rel="noopener"
 &gt;Amazon CloudFront Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&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 Differences&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://www.amazonaws.cn/getting-started/use-cases/cloudfront-network-acceleration/?nc1=h_ls" target="_blank" rel="noopener"
 &gt;Network Acceleration with Amazon CloudFront in China&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

 &lt;blockquote&gt;
 &lt;p&gt;&lt;strong&gt;Original Post:&lt;/strong&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 Mini-Guide (Part 8) - Deploy Free Certificates with China CloudFront and CloudFront SSL Plugin&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a class="link" href="https://github.com/aws-samples/China-CloudFront-SSL-Plugin" target="_blank" rel="noopener"
 &gt;aws-samples/China-CloudFront-SSL-Plugin&lt;/a&gt;&lt;/p&gt;

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