Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过python脚本使用SNS API设置SetPlatformApplication属性_Python_Amazon Web Services_Amazon Sns - Fatal编程技术网

如何通过python脚本使用SNS API设置SetPlatformApplication属性

如何通过python脚本使用SNS API设置SetPlatformApplication属性,python,amazon-web-services,amazon-sns,Python,Amazon Web Services,Amazon Sns,我试图通过python使用boto3库为SNS主题设置Platfrom应用程序属性 下面是脚本的片段 client1 = boto3.client('sns',region_name="us-east-1",aws_access_key_id=access_key,aws_secret_access_key=secret_access_key) def getSNSattr(): response = client1.set_platform_application_attribute

我试图通过python使用boto3库为SNS主题设置Platfrom应用程序属性

下面是脚本的片段

client1 = boto3.client('sns',region_name="us-east-1",aws_access_key_id=access_key,aws_secret_access_key=secret_access_key)

def getSNSattr():
    response = client1.set_platform_application_attributes(
    PlatformApplicationArn='arn:aws:sns:us-east-1:63124104179:testTop1',
    Attributes={
        'key':'SuccessFeedbackSampleRate',
        'value':'100'
    }
    )
下面是我得到的错误。aws文档中没有python示例,也没有太多帮助。我不确定我在这里错过了什么。请帮忙

*Traceback (most recent call last):
  File "sns2.py", line 20, in <module>
    getSNSattr()
  File "sns2.py", line 15, in getSNSattr
    'key': 'SuccessFeedbackSampleRate'
  File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 317, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 615, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameter) when calling the SetPlatformApplicationAttributes operation: Invalid parameter: PlatformApplicationArn Reason: Wrong number of slashes in relative portion of the ARN.*
*回溯(最近一次呼叫最后一次):
文件“sns2.py”,第20行,在
getSNSattr()
getSNSattr中第15行的文件“sns2.py”
“键”:“SuccessFeedbackSampleRate”
文件“/usr/local/lib/python2.7/site packages/botocore/client.py”,第317行,在api调用中
返回self.\u make\u api\u调用(操作名称,kwargs)
文件“/usr/local/lib/python2.7/site packages/botocore/client.py”,第615行,在make\u api\u调用中
引发错误\u类(解析的\u响应、操作\u名称)
botocore.errorfactory.InvalidParameterException:调用SetPlatformApplicationAttributes操作时发生错误(InvalidParameter):无效参数:PlatformApplicationArn原因:ARN相对部分的斜杠数错误*
AWS文件供参考:


您在PlatformApplicationArn中放置的ARN不是平台ARN,而是主题ARN。如果要设置主题的属性,请考虑使用。我还将使用双引号,因为属性是JSON格式的

所有这些都可以使用AWS CLI轻松测试:

$ aws sns get-platform-application-attributes --platform-application-arn arn:aws:sns:us-east-1:123456789012:app/GCM/My_App

{
    "Attributes": {
        "FailureFeedbackRoleArn": "arn:aws:iam::123456789012:role/SNSFailureFeedback",
        "EventDeliveryFailure": "arn:aws:sns:us-east-1:123456789012:Test",
        "EventEndpointDeleted": "arn:aws:sns:us-east-1:123456789012:Test",
        "EventEndpointUpdated": "arn:aws:sns:us-east-1:123456789012:Test",
        "Enabled": "true",
        "EventEndpointCreated": "arn:aws:sns:us-east-1:123456789012:Test",
        "SuccessFeedbackRoleArn": "arn:aws:iam::123456789012:role/SNSSuccessFeedback"
    }
}

$ aws sns set-platform-application-attributes --platform-application-arn arn:aws:sns:us-east-1:123456789012:app/GCM/My_App --attributes '{"SuccessFeedbackSampleRate": "100"}'

$ aws sns get-platform-application-attributes --platform-application-arn arn:aws:sns:us-east-1:123456789012:app/GCM/My_App

{
    "Attributes": {
        "FailureFeedbackRoleArn": "arn:aws:iam::123456789012:role/SNSFailureFeedback",
        "EventDeliveryFailure": "arn:aws:sns:us-east-1:123456789012:Test",
        "EventEndpointDeleted": "arn:aws:sns:us-east-1:123456789012:Test",
        "SuccessFeedbackSampleRate": "100",
        "EventEndpointUpdated": "arn:aws:sns:us-east-1:123456789012:Test",
        "Enabled": "true",
        "EventEndpointCreated": "arn:aws:sns:us-east-1:123456789012:Test",
        "SuccessFeedbackRoleArn": "arn:aws:iam::123456789012:role/SNSSuccessFeedback"
    }
}
如果要为应用程序设置属性,请将SetPlatformApplicationAttributes API与应用程序ARN一起使用;如果要为主题设置属性,请将SetTopicAttributes API与主题ARN一起使用。还可以使用双引号,因为属性是JSON格式的

代码应该如下所示:

def getSNSattr():
    response = client1.set_platform_application_attributes(
    PlatformApplicationArn="arn:aws:sns:us-east-1:63124104179:app/GCM/testApp1",
    Attributes={
        "SuccessFeedbackSampleRate":"100"
    }
    )