Skip to content

Instantly share code, notes, and snippets.

@zaru
Created March 23, 2020 09:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zaru/ff1b07872c6d8b0499aa71f1beb98429 to your computer and use it in GitHub Desktop.
Save zaru/ff1b07872c6d8b0499aa71f1beb98429 to your computer and use it in GitHub Desktop.
AWS SNS publish api curl request
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