0

I have an EC2 instance in region EU-CENTRAL-1 which runs a docker image. The docker image needs to be able to send an sms via SNS in region EU-WEST-1.

As of my understanding the instance should by default be able to access the internet outside with a security group letting all outbound communication through. But do i have to setup something to allow the the instance access to SNS in Ireland?

I'm using the following code, but AWS responds as if i used SNS in EU-CENTRAL-1 region where SMS is not available.

// Setup AWS SNS
        AWS.config.update({
          region: 'eu-west-1',
          accessKeyId: process.env.AWS_ACCESS_KEY_ID,
          secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
        });
        var sns = new AWS.SNS();


        var params = {
          Message: "SMS message test",
          MessageStructure: 'string',
          PhoneNumber: '0045xxxxxxxx',
          Subject: 'Alarm',
          MessageAttributes :{
            'AWS.SNS.SMS.SenderID': {
              'DataType': 'String',
              'StringValue': 'MySender'
            },
            'AWS.SNS.SMS.SMSType': 'Transactional'
          }
        }; 
Peter Savnik
  • 763
  • 1
  • 8
  • 27
  • For me a better approach is to call an API-Gateway endpoint that will execute a lambda function. It's cleaner and better for maintenance. If you like this idea, let me know and I put the steps in an answer. – Ele Jan 08 '18 at 15:03
  • @EleazarEnrique I would like to see that solution. thanks – Rodrigo Murillo Jan 08 '18 at 15:05
  • @RodrigoM take a look at https://stackoverflow.com/questions/48194394/is-there-a-best-approach-to-deploy-an-architecture-to-send-sms-using-a-microserv/48194395 – Ele Jan 10 '18 at 19:02

2 Answers2

1

You have to set the region when you instantiate the variable sns:

var sns = new AWS.SNS({region:'eu-west-1'});
TheOni
  • 810
  • 9
  • 26
  • I actually tried this way to compare the with setting the region in AWS Update config. There was no difference. But I guess if I had to use multiple services from AWS within the same nodejs script across regions - your answer is the right way to make only the SNS service use EU-WEST-1. – Peter Savnik Jan 10 '18 at 08:10
  • @PeterSavnik yes, setting the region in the object creation allows you to have a better control on the region you use – TheOni Jan 10 '18 at 11:50
1

I resolved the problem by finding the instance the docker images was running on and editing the IAM role to allow it to access SNS. After rebooting the instance the SNS service is working perfect.

Peter Savnik
  • 763
  • 1
  • 8
  • 27