flask - 我可以将 AWS Lambda 站点移动到私有(private)域吗?

标签 flask lambda zappa

我正在使用 Zappa 部署 Flask 应用程序。它有效(site)。显然,我不希望它停留在 aws 域后面并将其放在我的个人域中。

我正在搜索的所有内容都在谈论使用 S3 和 API Gateway 托管 Lambda 站点。有没有办法将我的小应用程序部署到自定义域?

编辑

在@mislav 的回答之后,我能够让我的谷歌域与 AWS 一起工作。但是当我尝试通过运行 zappa certify 来完成时我收到有关现有域的错误:

raise error_class(parsed_response, operation_name) botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the CreateDomainName operation: The domain name you provided already exists.



我的 zappa_settings.json
{
"dev": {
    "app_function": "ping_app.app",
    "aws_region": "us-west-1",
    "profile_name": "Breuds",
    "project_name": "breuds",
    "runtime": "python3.6",
    "s3_bucket": "zappa-ping-redshift",
    "slim_handler": true,
    "certificate_arn": "arn:aws:acm:us-east-1:010174774769:certificate/3a92c204-5788-42fc-bc65-74aaae8c1b3f",
    "domain": "breuds.com"
}
}

我开始认为我在我的域方面做一些令人费解的事情。我正在使用 Google Domains(因为我的电子邮件有一个自定义域,只是使用它),但这似乎会导致试图让 AWS 与之交谈令人头疼。

最佳答案

zappa’s readme中其实有解释.

Deploying to a Domain With AWS Certificate Manager

Amazon provides their own free alternative to Let's Encrypt called AWS Certificate Manager (ACM). To use this service with Zappa:

Verify your domain in the AWS Certificate Manager console. In the console, select the N. Virginia (us-east-1) region and request a certificate for your domain or subdomain (sub.yourdomain.tld), or request a wildcard domain (*.yourdomain.tld). Copy the entire ARN of that certificate and place it in the Zappa setting certificate_arn. Set your desired domain in the domain setting. Call $ zappa certify to create and associate the API Gateway distribution using that certificate.



还有使用现有证书等的说明。

不要让它愚弄你,这部分的标题听起来像是关于证书的,但是有关于使用你自己的域的详细说明。

编辑:
我包括 my own zappa settings以供引用。
{
    "common": {
        "app_function": "app.__hug_wsgi__",
        "aws_region": "eu-central-1",
        "s3_bucket": "excuse-generator",
        "profile_name": "mislavcimpersak",
        "remote_env": "s3://excuse-generator/secrets.json",
        "certificate_arn": "arn:aws:acm:us-east-1:500819636056:certificate/3edb9c1c-12c5-4601-89a9-dc42df840fa6"
    },
    "prod": {
        "extends": "common",
        "domain": "function.xkcd-excuse.com"
    },
    "dev": {
        "extends": "common",
        "debug": true,
        "keep_warm": false,
        "domain": "function-dev.xkcd-excuse.com"
        }
    }

在 namecheap.com 上购买并通过 cloudflare.com 提供服务的域名的分步指南
  • 在 namecheap.com 上购买域名/使用现有的
  • 在 cloudflare.com 上注册新站点/使用现有的
  • cloudflare 会给你(很可能)两个域名服务器
  • https://ap.www.namecheap.com/domains/domaincontrolpanel/xkcd-excuse.com/domain 下输入DNS - 选择 cloudflare 上提供的“自定义 DNS”名称服务器
  • 转到 AWS ACM 并申请新证书(证书必须在 us-east-1 区域创建)
  • 如有必要,输入多个子域(foo.example.com & foo-dev.example.com)
  • 记下 AWS 管理控制台
  • 提供的 ACM ARN
  • zappa_settings.jsoncertificate_arn 下输入您的 ARN
  • zappa_settings.jsonroute53_enabled 下把 false - 这是必须的
  • zappa_settings.jsondomain 下输入每个阶段的域,即。 foo.example.comfoo-dev.example.com
  • 运行 zappa certify <stage_name>
  • 它应该说:“使用提供的证书创建了一个新域名。请注意,创建并通过 AWS 传播此域最多可能需要 40 分钟,但您不需要做进一步的工作。
    证书已更新!”
  • 进入 CloudFlare DNS 界面并输入
  • CNAME: foo - i3jtsjkdeu4wxo.cloudfront.net
  • CNAME: foo-dev - d2jtsjkdeu4wxo.cloudfront.net
  • 等待 40 分钟并检查您的域,它们应该为您的 Lambda 函数提供服务
  • 关于flask - 我可以将 AWS Lambda 站点移动到私有(private)域吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47604237/

    相关文章:

    angularjs - 如何将 lambda 表达式传递给 AngularJS 指令

    python - Flask-ask 无法部署 zappa

    python-3.x - 没有 API 网关的 Zappa Python 3.6 Lambda 函数

    flask - 检查 Flask html 页面中的变量条件

    python - 有或没有蓝图的两种语言 Flask 网站

    python - 为什么涉及 list.index() 调用的 lambda 如此慢?

    c# - lambda 外部子查询迭代变量评估的次数

    python-3.x - Zappa/异步AWS Lambda函数在30秒内超时

    Python Eve Auth 无法返回 401 异常

    python - 我无法在 WSL Ubuntu 上使用 pip