如何使用对流层为 CloudFront 分配设置 cookie?
How do I set cookies for CloudFront distribution using 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 模板。但我还需要转发cookies。在 QueryString
行之后我插入了 Cookies = "All"
但这导致构建失败。
错误信息:
TypeError: <class 'troposphere.cloudfront.ForwardedValues'>: None.Cookies is <class 'str'>, expected <class 'troposphere.cloudfront.Cookies'>
我需要添加什么才能使构建和转发 cookie 不会失败
我看完这篇就搞定了document
行后QueryString = True,
我加了
Cookies = Cookies(Forward = "all"),
它现在可以毫无错误地构建并将正确的 cookie 值添加到 json 模板
使用 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 模板。但我还需要转发cookies。在 QueryString
行之后我插入了 Cookies = "All"
但这导致构建失败。
错误信息:
TypeError: <class 'troposphere.cloudfront.ForwardedValues'>: None.Cookies is <class 'str'>, expected <class 'troposphere.cloudfront.Cookies'>
我需要添加什么才能使构建和转发 cookie 不会失败
我看完这篇就搞定了document
行后QueryString = True,
我加了
Cookies = Cookies(Forward = "all"),
它现在可以毫无错误地构建并将正确的 cookie 值添加到 json 模板