An example SAM template for a Lambda & API Gateway app that sends messages using SNS
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: 'AWS::Serverless-2016-10-31' | |
Description: An example SAM template for a Lambda & API Gateway app that sends messages using SNS. | |
Parameters: | |
# For any variables you don't want stored in your repo, you can pass them through the SAM deploy command | |
# Ie, sam deploy .... --parameter-overrides MyEmail=myemail@gmail.com | |
MyEmail: | |
Type: String | |
Resources: | |
SendMessageFunction: | |
Type: 'AWS::Serverless::Function' | |
Properties: | |
FunctionName: SendMessageFunction | |
Handler: SendMessageFunction.lambda_handler | |
Runtime: python3.7 | |
CodeUri: ./SendMessageFunction | |
Description: A function that sends a message through SNS when invoked by API Gateway. | |
Policies: | |
# Read more about SAM policy templates here | |
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html | |
- SNSPublishMessagePolicy: | |
TopicName: !GetAtt MySnsTopic.TopicName | |
Environment: | |
Variables: | |
# Include the SNS topic ARN as an env var so that you can reference it in this function's code. | |
SNS_TOPIC_ARN: !Ref MySnsTopic | |
Events: | |
SendMessageApi: | |
# An API Gateway endpoint that responds to HTTP GET | |
Type: Api | |
Properties: | |
Path: /send_message | |
Method: GET | |
MySnsTopic: | |
Type: AWS::SNS::Topic | |
Properties: | |
Subscription: | |
- Protocol: email | |
Endpoint: !Ref MyEmail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment