代码之家  ›  专栏  ›  技术社区  ›  nad87563

无法分析aws cli中的json字符串以将通知配置添加到s3 bucket

  •  0
  • nad87563  · 技术社区  · 7 年前

    我试图将sns主题添加到s3 bucket中,并使用aws cli命令将一个名为“test”的通知配置应用到s3bucket

    我将sns主题配置作为json字符串传递,当我试图打印json字符串时,它会正确地打印json值,但无论如何aws cli会在json字符串中添加逗号。

    inputEvent.sh:输入事件:

    #!/bin/bash
    bucketName=test
    jsonInput=file:///Users/ish/GitLabProject/validator-cf/inputevent.json
    QueueArn="arn:aws:sns:us-east-1:255353535355:SNSTopic"
    template='{ "TopicConfigurations": { "Event": "s3:ObjectCreated:*", "Queue": "%s" } }'
    
    
    TopicConfiguration=$(printf "$template" "$QueueArn")
    
    echo "$TopicConfiguration"
    
    aws s3api put-bucket-notification-configuration --bucket $bucketName --notification-configuration $TopicConfiguration
    

    错误:

    { "TopicConfigurations": { "Event": "s3:ObjectCreated:*", "Queue": "arn:aws:sns:us-east-1:255353535355:SNSTopic" } }
    usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
    To see help text, you can run:
    
      aws help
      aws <command> help
      aws <command> <subcommand> help
    
    Unknown options: {, "Event":, "s3:ObjectCreated:*",, "Queue":, "arn:aws:sns:us-east-1:255353535355:SNSTopic", }, }, "TopicConfigurations":
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   maafk    7 年前

    检查你的 template 变量。

    基于 docs , the TopicConfigurations --notification-configuration 应该是数组(因为可以有多个通知)

    尝试更新 模板 bash脚本中的变量

    template='{ "TopicConfigurations": [{ "Event": "s3:ObjectCreated:*", "Queue": "%s" }] }'
    

    可以检查 examples 为了得到更好的主意