如何使用对流层为CloudFront分配设置cookie?

时间:2019-07-10 22:18:39

标签: cookies amazon-cloudfront troposphere

在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

1 个答案:

答案 0 :(得分:0)

我在读完此document

后得出了结论

QueryString = True,行之后 我添加了

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