admin管理员组文章数量:1389768
I am trying to add a cloudfront behavior to my an origin and I am getting InvalidArgument: The parameter CachedMethods is required. While the aws sdk go v2 says cache method is deprecated.
func AddCloudFrontBehavior(client *cloudfront.Client, distributionID, originID, pathPattern string) error {
distribution, err := client.GetDistributionConfig(context.TODO(), &cloudfront.GetDistributionConfigInput{
Id: aws.String(distributionID),
})
if err != nil {
return fmt.Errorf("failed to get CloudFront distribution: %v", err)
}
// Create new behavior
newBehavior := cloudfrontTypes.CacheBehavior{
TargetOriginId: aws.String(originID),
PathPattern: aws.String(pathPattern),
ViewerProtocolPolicy: cloudfrontTypes.ViewerProtocolPolicyAllowAll,
AllowedMethods: &cloudfrontTypes.AllowedMethods{
Quantity: aws.Int32(2),
Items: []cloudfrontTypes.Method{
cloudfrontTypes.MethodGet,
cloudfrontTypes.MethodHead,
// cloudfrontTypes.MethodPost,
// cloudfrontTypes.MethodPut,
// cloudfrontTypes.MethodDelete,
// cloudfrontTypes.MethodOptions,
// cloudfrontTypes.MethodPatch,
},
},
Compress: aws.Bool(true),
SmoothStreaming: aws.Bool(false),
MinTTL: aws.Int64(0),
ForwardedValues: &cloudfrontTypes.ForwardedValues{
QueryString: aws.Bool(false),
Cookies: &cloudfrontTypes.CookiePreference{
Forward: cloudfrontTypes.ItemSelectionAll,
},
Headers: &cloudfrontTypes.Headers{
Quantity: aws.Int32(0),
},
QueryStringCacheKeys: &cloudfrontTypes.QueryStringCacheKeys{
Quantity: aws.Int32(0),
},
},
DefaultTTL: aws.Int64(0),
MaxTTL: aws.Int64(3600),
FieldLevelEncryptionId: aws.String(""),
// CachePolicyId: aws.String(originID),
// OriginRequestPolicyId: aws.String(originID),
}
// Append to cache behaviors
distribution.DistributionConfig.CacheBehaviors.Items = append(distribution.DistributionConfig.CacheBehaviors.Items, newBehavior)
distribution.DistributionConfig.CacheBehaviors.Quantity = aws.Int32(int32(len(distribution.DistributionConfig.CacheBehaviors.Items)))
// Update distribution
_, err = client.UpdateDistribution(context.TODO(), &cloudfront.UpdateDistributionInput{
Id: aws.String(distributionID),
DistributionConfig: distribution.DistributionConfig,
IfMatch: distribution.ETag,
})
if err != nil {
return fmt.Errorf("failed to update CloudFront distribution: %v", err)
}
fmt.Println("CloudFront behavior added successfully!")
return nil
}type here
I am trying to add a cloudfront behavior to my an origin and I am getting InvalidArgument: The parameter CachedMethods is required. While the aws sdk go v2 says cacheMethod is deprecated.
I am trying to add a cloudfront behavior to my an origin and I am getting InvalidArgument: The parameter CachedMethods is required. While the aws sdk go v2 says cache method is deprecated.
func AddCloudFrontBehavior(client *cloudfront.Client, distributionID, originID, pathPattern string) error {
distribution, err := client.GetDistributionConfig(context.TODO(), &cloudfront.GetDistributionConfigInput{
Id: aws.String(distributionID),
})
if err != nil {
return fmt.Errorf("failed to get CloudFront distribution: %v", err)
}
// Create new behavior
newBehavior := cloudfrontTypes.CacheBehavior{
TargetOriginId: aws.String(originID),
PathPattern: aws.String(pathPattern),
ViewerProtocolPolicy: cloudfrontTypes.ViewerProtocolPolicyAllowAll,
AllowedMethods: &cloudfrontTypes.AllowedMethods{
Quantity: aws.Int32(2),
Items: []cloudfrontTypes.Method{
cloudfrontTypes.MethodGet,
cloudfrontTypes.MethodHead,
// cloudfrontTypes.MethodPost,
// cloudfrontTypes.MethodPut,
// cloudfrontTypes.MethodDelete,
// cloudfrontTypes.MethodOptions,
// cloudfrontTypes.MethodPatch,
},
},
Compress: aws.Bool(true),
SmoothStreaming: aws.Bool(false),
MinTTL: aws.Int64(0),
ForwardedValues: &cloudfrontTypes.ForwardedValues{
QueryString: aws.Bool(false),
Cookies: &cloudfrontTypes.CookiePreference{
Forward: cloudfrontTypes.ItemSelectionAll,
},
Headers: &cloudfrontTypes.Headers{
Quantity: aws.Int32(0),
},
QueryStringCacheKeys: &cloudfrontTypes.QueryStringCacheKeys{
Quantity: aws.Int32(0),
},
},
DefaultTTL: aws.Int64(0),
MaxTTL: aws.Int64(3600),
FieldLevelEncryptionId: aws.String(""),
// CachePolicyId: aws.String(originID),
// OriginRequestPolicyId: aws.String(originID),
}
// Append to cache behaviors
distribution.DistributionConfig.CacheBehaviors.Items = append(distribution.DistributionConfig.CacheBehaviors.Items, newBehavior)
distribution.DistributionConfig.CacheBehaviors.Quantity = aws.Int32(int32(len(distribution.DistributionConfig.CacheBehaviors.Items)))
// Update distribution
_, err = client.UpdateDistribution(context.TODO(), &cloudfront.UpdateDistributionInput{
Id: aws.String(distributionID),
DistributionConfig: distribution.DistributionConfig,
IfMatch: distribution.ETag,
})
if err != nil {
return fmt.Errorf("failed to update CloudFront distribution: %v", err)
}
fmt.Println("CloudFront behavior added successfully!")
return nil
}type here
I am trying to add a cloudfront behavior to my an origin and I am getting InvalidArgument: The parameter CachedMethods is required. While the aws sdk go v2 says cacheMethod is deprecated.
Share Improve this question asked Mar 14 at 9:24 Dingba NiceDingba Nice 132 bronze badges2 Answers
Reset to default 0CachedMethods
is required in AllowedMethods
, and is not deprecated.
ForwardedValues
is deprecated, though.
CloudFront still expects CachedMethods
when using ForwardedValues
. Although the AWS SDK v2 marks it as deprecated, u must explicitly set it when ForwardedValues
is defined.I think u should modify your newBehavior
struct by adding the CachedMethods
field under ForwardedValues
本文标签:
版权声明:本文标题:amazon web services - I am trying to add a cloudfront behavior to my an origin and I am getting InvalidArgument: The parameter C 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744664303a2618436.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论