Select your cookie preferences

We use cookies and similar tools to enhance your experience, provide our services, deliver relevant advertising, and make improvements. Approved third parties also use these tools to help us deliver advertising and provide certain site features.

Amazon API Gateway REST API with SNS SMS integration

Created with SnapAPI GatewaySNS

Send SMS messages from API Gateway using SNS

This sample project demonstrates how to send SMS messages using API Gateway.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: API to send SMS using SNS (uksb-1tthgi812) (tag:apigw-sns-sms)

Resources:
  RestApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
      DefinitionBody: # an OpenApi definition
        'Fn::Transform':
          Name: 'AWS::Include'
          Parameters:
            Location: './api.yaml'
      OpenApiVersion: 3.0.3
      EndpointConfiguration:
          Type: REGIONAL

  RootRole:
    Type: 'AWS::IAM::Role'
    Properties:
      RoleName: API-SNSSMS
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - apigateway.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      Policies:
        - PolicyName: SNS_SMS
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: [ "sns:Publish"]
                Resource: "*"
              - Effect: Deny
                Action: ["sns:Publish"]
                Resource: "arn:aws:sns:*:*"
              
Outputs:
  API:
    Description: API to send SMS using SNS
    Value: !Sub "https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/dev"

< Back to all patterns


GitHub icon Visit the GitHub repo for this pattern.

Download

git clone https://github.com/aws-samples/serverless-patterns/ cd serverless-patterns/apigw-sns-sms

Deploy

sam deploy --guided --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: sam delete.

Additional resources

Siddhi Jha

Presented by Siddhi Jha

A Serverless Cloud Engineer who works on building scalable, economic and sustainable solutions using AWS

Follow on LinkedIn