AWS CLI CloudFront使所有文件无效

时间:2016-06-11 04:32:34

标签: amazon-web-services command-line-interface amazon-cloudfront

我试图使整个静态网站无效。以下命令似乎不会使aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /* 无效,并且会使项目的奇数输出无效,如下所示。这个AWS CLI行为是正常还是我遗漏了什么?谢谢!

{
    "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
        }, 

输出:

#Add a fourth parameter, end, to the find function that specifies where to stop looking. Warning: This exercise is a bit tricky. The default value of end should be len(str), but that doesn't work. The default values are evaluated when the function is defined, not when it is called. When find is defined, str doesn't exist yet, so you can’t find its length.

3 个答案:

答案 0 :(得分:34)

那是你的shell expansion of local filenames

这是你基本上要求的,因为*没有被引用。

--paths '*'指定--paths '/*'¹将执行您的操作。引用通配符会将其保留为文字字符串而不是您所看到的字符串。

¹CloudFront控制台允许您指定*/*以使整个发布无效;相反,CLI期望/*。反过来,这是因为底层API也需要/*。在控制台中使用*时,控制台会在控制台向CloudFront API发出请求之前以静默方式添加前导斜杠。

答案 1 :(得分:2)

通过aws cli使云面分配无效的示例:

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

示例:

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

要列出或获取Cloudfront发行ID,您可以使用控制台或通过cli:

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

答案 2 :(得分:-1)

"/*" 只会使根目录中的对象无效。

您可以发送多个通配符路径来使 N 个文件夹级别层次结构中的所有文件无效。例如达到 5 个级别的深度:

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