29/01/2021 - AWS
Amazon Simple Notification Service (SNS) ile "abonelik" ve "yayımlamak" özellikler kullanırken arada abonelik "onay" aşaması vardır. Birisi bir "uç noktaya" (endpoint) abone olduktan sonra, Amazon SNS bir abonelik onay mesajı gönderir. Bir email
"protokolü" (protocol) "uç nokta" (endpoint) olarak kullanılmışsa, belirlenen e-posta adresine bir mesaj gönderilir. Bir http/https
"protokolü" (protocol) "uç nokta" (endpoint) olarak kullanılmışsa, belirlenen URL adresine bir HTTP POST request gönderilir. Her iki durumda da mesaj içeriği SubscriptionURL
verisine sahip olacaktır. Aboneliği onaylamak için bu URL'nin ziyaret edilmesi gerekir, aksi takdirde bir şey yayınlandığında orijinal abonelik dikkate alınmayacaktır. Ziyaret edilen URL'nin başarılı yanıtı (200 OK
) XML olacaktır ve SubscriptionArn
ile RequestId
özelliklerini içerecektir.
Testimde https
protokolü ve https://asd34hjfd.m.pipedream.net/
uç noktası ile kullandım. İsterseniz bunun yerine email
protokolü ve bir email adres kullanabilirsiniz.
Amazon'dan alacağınız şey bu.
{
"headers": {
"host": "asd34hjfd.m.pipedream.net",
"x-amzn-trace-id": "Root=1-60146237-1bb8db87053a3fa237869185",
"content-length": "697",
"user-agent": "Amazon Simple Notification Service Agent",
"accept-encoding": "gzip, deflate",
"accept": "*/*",
"content-type": "text/plain",
"x-amz-sns-message-type": "SubscriptionConfirmation",
"x-amz-sns-topic-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"x-amz-sns-subscription-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter:44980782-18b0-4596-aee3-144f3f47dedf"
},
"body": {
"Type": "SubscriptionConfirmation",
"MessageId": "718e57b1-076f-4d95-929e-99996c34209d",
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"Message": "You have chosen to subscribe to the topic arn:aws:sns:eu-west-1:000000000000:newsletter.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
"Timestamp": "2021-01-29T19:29:57.582Z",
"SignatureVersion": "1",
"Signature": "EXAMPLEpH+..",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem",
"SubscribeURL": "http://localhost:4566/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:eu-west-1:000000000000:newsletter&Token=90a9c15d",
"Token": "90a9c15d"
},
"inferred_body_type": "JSON",
"method": "POST",
"url": "https://asd34hjfd.m.pipedream.net/",
"client_ip": "1.10.40.10",
"query": {
}
}
Yukarıdaki aboneliği onayladıktan sonra, bu https://asd34hjfd.m.pipedream.net/
uç noktanızın POST isteği olarak alacağı şeydir. hello
mesajını yayınladım.
{
"headers": {
"host": "asd34hjfd.m.pipedream.net",
"x-amzn-trace-id": "Root=1-6014626e-0703d14767d4d65d2a957a97",
"content-length": "363",
"user-agent": "Amazon Simple Notification Service Agent",
"accept-encoding": "gzip, deflate",
"accept": "*/*",
"content-type": "text/plain",
"x-amz-sns-message-type": "Notification",
"x-amz-sns-topic-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"x-amz-sns-subscription-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter:44980782-18b0-4596-aee3-144f3f47dedf"
},
"body": {
"Type": "Notification",
"MessageId": "7983a6d0-d1af-4846-977f-b14aa5e040a5",
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"Message": "hello",
"Timestamp": "2021-01-29T19:30:53.973Z",
"SignatureVersion": "1",
"Signature": "EXAMPLEpH+..",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem"
},
"inferred_body_type": "JSON",
"method": "POST",
"url": "https://asd34hjfd.m.pipedream.net/",
"client_ip": "1.10.40.10",
"query": {
}
}
$ aws --profile localstack --endpoint-url http://localhost:4566 sns create-topic --name newsletter
{
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:newsletter"
}
$ aws --profile localstack --endpoint-url http://localhost:4566 sns subscribe --topic-arn arn:aws:sns:eu-west-1:000000000000:newsletter --protocol https --notification-endpoint https://efs324vfd43.m.pipedream.net
{
"SubscriptionArn": "arn:aws:sns:eu-west-1:000000000000:newsletter:43014665-f108-4176-96ef-121382da3776"
}
Bu, abonelik ayrıntılarıdır.
$ aws --profile localstack --endpoint-url http://localhost:4566 sns list-subscriptions
{
"Subscriptions": [
{
"SubscriptionArn": "arn:aws:sns:eu-west-1:000000000000:newsletter:43014665-f108-4176-96ef-121382da3776",
"Owner": "",
"Protocol": "https",
"Endpoint": "https://efs324vfd43.m.pipedream.net",
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:newsletter"
}
]
}
Uç noktanızın alacağı budur ve SubscriptionURL
adresini ziyaret etmeniz gerekecek. Ziyaret edildiğinde, yukarıda açıklandığı gibi bir 200 OK
XML yanıtı döndürülür.
{
"headers": {
"host": "efs324vfd43.m.pipedream.net",
"x-amzn-trace-id": "Root=1-60147dc0-45ac810e098a1f4a57c5a652",
"content-length": "697",
"user-agent": "Amazon Simple Notification Service Agent",
"accept-encoding": "gzip, deflate",
"accept": "*/*",
"content-type": "text/plain",
"x-amz-sns-message-type": "SubscriptionConfirmation",
"x-amz-sns-topic-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"x-amz-sns-subscription-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter:43014665-f108-4176-96ef-121382da3776"
},
"body": {
"Type": "SubscriptionConfirmation",
"MessageId": "97c3152b-7a51-4cc1-85fb-a05c5e00bac6",
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"Message": "You have chosen to subscribe to the topic arn:aws:sns:eu-west-1:000000000000:newsletter.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
"Timestamp": "2021-01-29T21:27:27.739Z",
"SignatureVersion": "1",
"Signature": "EXAMPLEpH+..",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem",
"SubscribeURL": "http://localhost:4566/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:eu-west-1:000000000000:newsletter&Token=555f40e4",
"Token": "555f40e4"
},
"inferred_body_type": "JSON",
"method": "POST",
"url": "https://efs324vfd43.m.pipedream.net/",
"client_ip": "1.15.10.10",
"query": {
}
}
$ aws --profile localstack --endpoint-url http://localhost:4566 sns publish --topic-arn arn:aws:sns:eu-west-1:000000000000:newsletter --message "hello"
{
"MessageId": "b774ac11-acc9-4c28-b0dd-a4aeeaceb58d"
}
Bu, uç noktanızın alacağı istektir.
{
"headers": {
"host": "efs324vfd43.m.pipedream.net",
"x-amzn-trace-id": "Root=1-60147ee8-4d11aef729aa6bb6192fbcfc",
"content-length": "363",
"user-agent": "Amazon Simple Notification Service Agent",
"accept-encoding": "gzip, deflate",
"accept": "*/*",
"content-type": "text/plain",
"x-amz-sns-message-type": "Notification",
"x-amz-sns-topic-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"x-amz-sns-subscription-arn": "arn:aws:sns:eu-west-1:000000000000:newsletter:43014665-f108-4176-96ef-121382da3776"
},
"body": {
"Type": "Notification",
"MessageId": "b774ac11-acc9-4c28-b0dd-a4aeeaceb58d",
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:newsletter",
"Message": "hello",
"Timestamp": "2021-01-29T21:32:23.540Z",
"SignatureVersion": "1",
"Signature": "EXAMPLEpH+..",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem"
},
"inferred_body_type": "JSON",
"method": "POST",
"url": "https://efs324vfd43.m.pipedream.net/",
"client_ip": "1.15.10.10",
"query": {
}
}