-
-
Save afalahi/7908784e3284e1e6762c8c8fdfc53814 to your computer and use it in GitHub Desktop.
AWS SNS publish api curl request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'aws-sigv4' | |
require 'active_support/core_ext' | |
params = { | |
'Action' => 'Publish', | |
'TargetArn' => 'arn:aws:sns:ap-northeast-1:000000000000:example-topic', | |
'Message' => 'message', | |
'Version' => '2010-03-31' | |
}.to_query | |
signer = Aws::Sigv4::Signer.new( | |
service: 'sns', | |
region: 'ap-northeast-1', | |
access_key_id: ENV['AWS_ACCESS_KEY_ID'], | |
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], | |
session_token: ENV['AWS_SESSION_TOKEN'] # use STS | |
) | |
signature = signer.sign_request( | |
http_method: 'GET', | |
url: 'https://sns.ap-northeast-1.amazonaws.com/?' + params | |
) | |
cmd = <<EOS | |
curl -X GET \ | |
-H 'host: #{signature.headers['host']}' \ | |
-H 'x-amz-content-sha256: #{signature.headers['x-amz-content-sha256']}' \ | |
-H 'x-amz-date: #{signature.headers['x-amz-date']}' \ | |
-H 'x-amz-security-token: #{signature.headers['x-amz-security-token']}' \ | |
-H 'authorization: #{signature.headers['authorization']}' \ | |
'https://sns.ap-northeast-1.amazonaws.com/?#{params}' | |
EOS | |
puts cmd | |
puts system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment