Skip to content

Instantly share code, notes, and snippets.

@tkeeber
Last active March 17, 2021 01:05
Show Gist options
  • Save tkeeber/a1bc17dc9cefd954d8c87f810be56107 to your computer and use it in GitHub Desktop.
Save tkeeber/a1bc17dc9cefd954d8c87f810be56107 to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Api Gateway to SNS topic
Resources:
StatsApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
swagger: "2.0"
info:
version: "v1"
title: !Ref AWS::StackName
paths:
/stats:
post:
responses:
"202":
description: Accepted
x-amazon-apigateway-integration:
type: "aws"
httpMethod: "POST"
uri: !Sub "arn:aws:apigateway:${AWS::Region}:sns:action/Publish"
credentials: !GetAtt StatsApiRole.Arn
requestParameters:
integration.request.querystring.Message: "method.request.body"
integration.request.querystring.TopicArn: !Sub "'${StatsTopic}'"
responses:
default:
statusCode: 202
StatsApiRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "apigateway.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
- PolicyName: !Sub "${AWS::StackName}-topic-policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action: "sns:Publish"
Effect: "Allow"
Resource: !Ref StatsTopic
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
StatsTopic:
Type: AWS::SNS::Topic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment