2017-09-01 49 views
0

爲什麼我不能訂閱AmazonIpSpaceChanged上的SNS?請檢查,我需要你的指導。AmazonIpSpaceChanged在不同地區的SNS訂閱錯誤

我基本遵循的指南是來自AWS Security博客的How to Automatically Update Your Security Groups for Amazon CloudFront and AWS WAF by Using AWS Lambda

這裏的端子的輸出:

 
➜ terminal $ cat ~/.aws/config 
[default] 
region = ap-southeast-1 
➜ terminal $ aws sns subscribe --topic-arn arn:aws:sns:us-east-1:806199016981:AmazonIpSpaceChanged --protocol lambda --notification-endpoint arn:aws:lambda:ap-southeast-1:accountid_removed:function:cloudfront-securitygroup-controller 

An error occurred (InvalidParameter) when calling the Subscribe operation: Invalid parameter: TopicArn 
➜ terminal $ AWS_REGION=ap-southeast-1 aws sns subscribe --topic-arn arn:aws:sns:ap-southeast-1:806199016981:AmazonIpSpaceChanged --protocol lambda --notification-endpoint arn:aws:lambda:ap-southeast-1:accountid_removed:function:cloudfront-securitygroup-controller 

An error occurred (AuthorizationError) when calling the Subscribe operation: User: arn:aws:iam::accountid_removed:user/[email protected] is not authorized to perform: SNS:Subscribe on resource: arn:aws:sns:ap-southeast-1:806199016981:AmazonIpSpaceChanged 

這也是當通過AWS Web控制檯完成輸出:

User: arn:aws:iam::accountid_removed:user/[email protected] is not authorized to perform: SNS:Subscribe on resource: arn:aws:sns:ap-southeast-1:806199016981:AmazonIpSpaceChanged (Service: AmazonSNS; Status Code: 403; Error Code: AuthorizationError; Request ID: 0e87384a-e298-569e-bf2d-6a5718eedc40) 

回答

1

這個錯誤是因爲你的API調用,必須對製造us-east-1區域,Amazon SNS主題所在的區域。

$ aws sns subscribe --topic-arn arn:aws:sns:us-east-1:806199016981:AmazonIpSpaceChanged --protocol email --notification-endpoint [email protected] --region us-east-1 
{ 
    "SubscriptionArn": "pending confirmation" 
} 

看來,在不同的區域訂閱一個AWS lambda函數也工作(或者,至少沒有返回錯誤):

aws sns subscribe --topic-arn arn:aws:sns:us-east-1:806199016981:AmazonIpSpaceChanged --protocol lambda --notification-endpoint arn:aws:lambda:ap-southeast-2:123456789012:foo --region us-east-1 
{ 
    "SubscriptionArn": "arn:aws:sns:us-east-1:806199016981:AmazonIpSpaceChanged:37dab281-1e8f-16ba-8e4a-ef9de429101b" 
} 
+0

我最後一次測試了它與'AWS_REGION =我們-east-1'並且失敗了。 這是一件好事,你指出我需要使用'--region'參數,它的工作原理。 非常感謝! –