简体   繁体   English

AWS CLI CloudFront 使所有文件无效

[英]AWS CLI CloudFront Invalidate All Files

I am attempting to invalidate an entire static website.我试图使整个静态网站无效。 The following command does not seem to invalidate /index.html and gives an odd output of items to be invalided, as shown below.以下命令似乎不会使/index.html失效,并给出了要失效的项目的奇怪输出,如下所示。 Is this AWS CLI behaviour normal or am I missing something?这种 AWS CLI 行为是正常的还是我遗漏了什么? Thanks!谢谢!

aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /*

Output:输出:

{
    "Invalidation": {
    "Status": "InProgress", 
    "InvalidationBatch": {
        "Paths": {
            "Items": [
                "/lib32", 
                "/home", 
                "/vmlinuz", 
                "/core", 
                "/proc", 
                "/var", 
                "/dev", 
                "/usr", 
                "/etc", 
                "/initrd.img", 
                "/cdrom", 
                "/lost+found", 
                "/root", 
                "/tmp", 
                "/lib", 
                "/dead.letter", 
                "/lib64", 
                "/boot", 
                "/sys", 
                "/run", 
                "/bin", 
                "/sbin", 
                "/mnt", 
                "/opt", 
                "/snap", 
                "/media", 
                "/copyright", 
                "/srv"
            ], 
            "Quantity": 28
        }, 

That's your shell doing expansion of local filenames .那是你的 shell 进行 本地文件名的扩展

That's what you're essentially asking for since the * isn't quoted.这就是你本质上要求的,因为*没有被引用。

Either --paths '*' or Specifying --paths '/*' ¹ will do what you intend. 无论是 --paths '*'还是 指定--paths '/*' ¹ 都会做你想要的。 Quoting the wildcard keeps it as a literal string rather than what you're seeing.引用通配符会将其保留为文字字符串,而不是您看到的内容。


¹The CloudFront console allows you to specify either * or /* to invalidate the entire distribution; ¹CloudFront 控制台允许您指定*/*以使整个分配无效; by contrast, the CLI expects /* .相比之下,CLI 需要/* This, in turn, is because the underlying API also expects /* .反过来,这是因为底层 API 也需要/* When you use * in the console, the leading slash is silently added by the console before the console makes the request to the CloudFront API.当您在控制台中使用* ,在控制台向 CloudFront API 发出请求之前,控制台会以静默方式添加前导斜杠。

Example of invalidation of cloudfront distribution via aws cli :通过 aws cli 使 cloudfront 分发失效的示例:

aws cloudfront create-invalidation --distribution-id <DistributionID> --paths "/*"

Example :示例:

aws cloudfront create-invalidation --distribution-id E1B1A4GHK9TTE --paths "/*"

To list or get cloudfront distribution id you can use console or via cli :要列出或获取 cloudfront 分发 ID,您可以使用控制台或通过 cli :

aws cloudfront list-distributions 
aws cloudfront list-distributions | grep Id

"/*" will invalidate only the objects in the root. “/*”只会使根中的对象无效。

You can send multiple wildcard paths to invalidate all the files in N number of folder level hierarchy.您可以发送多个通配符路径以使 N 个文件夹级别层次结构中的所有文件无效。 For example to reach 5 levels in depth:例如要深入达到 5 个级别:

read -p "Cloud distribution: " clouddist
aws cloudfront create-invalidation --distribution-id $clouddist --paths "/*" "/*/*" "/*/*/*" "/*/*/*/*" "/*/*/*/*/*"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM