首页 > 解决方案 > 如何使用对流层为 CloudFront 分配设置 cookie?

问题描述

使用 troposhphere,我正在尝试创建 CloudFront 分配。

CacheBehaviors = [
                CacheBehavior(
                    TargetOriginId = Join("", ["cloudfront-", Ref("ParamOriginName")]),
                    PathPattern = '/en/Login/*',
                    AllowedMethods = ["GET", "HEAD", "OPTIONS", "PUT", "POST","PATCH"],
                    ForwardedValues = ForwardedValues(
                        QueryString = True,
                        Headers = ["user-agent",
                                "Host",
                                "CloudFront-Forwarded-Proto", 
                                "CloudFront-Is-Desktop-Viewer", 
                                "CloudFront-Is-Mobile-Viewer",
                                "CloudFront-Is-SmartTV-Viewer",
                                "CloudFront-Is-Tablet-Viewer",
                                "CloudFront-Viewer-Country",
                                "Origin",
                                "Referer"]
                        ),
                    MaxTTL = 86400,
                    MinTTL = 14400,
                    DefaultTTL = 43200,
                    ViewerProtocolPolicy = "redirect-to-https",
                    Compress = True,
                ),

这似乎可以很好地构建 json 模板。但我还需要转发 cookie。QueryString在我插入的行之后,Cookies = "All"但这使构建失败。

错误信息:
TypeError: <class 'troposphere.cloudfront.ForwardedValues'>: None.Cookies is <class 'str'>, expected <class 'troposphere.cloudfront.Cookies'>

我需要添加什么以便它不会使构建失败并转发 cookie

标签: cookiesamazon-cloudfronttroposphere

解决方案


我在阅读此文档后解决了

QueryString = True, 在我添加的行之后

Cookies = Cookies(Forward = "all"), 它现在构建没有错误,并将正确的 cookie 值添加到 json 模板


推荐阅读