serverless test
This commit is contained in:
parent
7a3474a139
commit
0e186728c2
97
serverless-upload.yaml
Normal file
97
serverless-upload.yaml
Normal file
@ -0,0 +1,97 @@
|
||||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Description: Serverless demo
|
||||
|
||||
Resources:
|
||||
# SNS Topic
|
||||
MySNSTopic:
|
||||
Type: AWS::SNS::Topic
|
||||
|
||||
# SQS Queue
|
||||
MySQSQueue:
|
||||
Type: AWS::SQS::Queue
|
||||
|
||||
# SNS Subscription to SQS
|
||||
SNSToSQSSubscription:
|
||||
Type: AWS::SNS::Subscription
|
||||
Properties:
|
||||
TopicArn: !Ref MySNSTopic
|
||||
Protocol: sqs
|
||||
Endpoint: !GetAtt MySQSQueue.Arn
|
||||
RawMessageDelivery: true
|
||||
|
||||
# SQS Queue Policy to Allow SNS to Send Messages
|
||||
SQSPolicy:
|
||||
Type: AWS::SQS::QueuePolicy
|
||||
Properties:
|
||||
Queues:
|
||||
- !Ref MySQSQueue
|
||||
PolicyDocument:
|
||||
Version: '2012-10-17'
|
||||
Statement:
|
||||
- Effect: Allow
|
||||
Principal:
|
||||
Service: sns.amazonaws.com
|
||||
Action: sqs:SendMessage
|
||||
Resource: !GetAtt MySQSQueue.Arn
|
||||
Condition:
|
||||
ArnEquals:
|
||||
aws:SourceArn: !Ref MySNSTopic
|
||||
|
||||
# API Gateway
|
||||
ApiGatewayRestApi:
|
||||
Type: AWS::ApiGateway::RestApi
|
||||
Properties:
|
||||
Name: SNSInvokeAPI
|
||||
Parameters:
|
||||
endpointConfigurationTypes: REGIONAL
|
||||
EndpointConfiguration:
|
||||
Types:
|
||||
- REGIONAL
|
||||
|
||||
# API Gateway Resource
|
||||
ApiGatewayResource:
|
||||
Type: AWS::ApiGateway::Resource
|
||||
Properties:
|
||||
ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
|
||||
PathPart: invoke
|
||||
RestApiId: !Ref ApiGatewayRestApi
|
||||
|
||||
# API Gateway Method to integrate directly with SNS
|
||||
ApiGatewayMethod:
|
||||
Type: AWS::ApiGateway::Method
|
||||
Properties:
|
||||
RestApiId: !Ref ApiGatewayRestApi
|
||||
ResourceId: !Ref ApiGatewayResource
|
||||
HttpMethod: POST
|
||||
AuthorizationType: NONE
|
||||
Integration:
|
||||
IntegrationHttpMethod: POST
|
||||
Type: AWS
|
||||
Uri: !Sub arn:aws:apigateway:${AWS::Region}:sns:path/Publish
|
||||
Credentials: "arn:aws:iam::920372985147:role/AWSAPIGateway"
|
||||
RequestParameters:
|
||||
integration.request.header.Content-Type: "'application/x-www-form-urlencoded'"
|
||||
RequestTemplates:
|
||||
application/json: !Sub |
|
||||
Action=Publish&TopicArn={!Ref MySNSTopic}&Message=$util.urlEncode($input.body)
|
||||
IntegrationResponses:
|
||||
- StatusCode: 200
|
||||
ResponseTemplates:
|
||||
application/json: '{"status": "Message published to SNS"}'
|
||||
MethodResponses:
|
||||
- StatusCode: 200
|
||||
|
||||
# API Gateway Deployment
|
||||
ApiGatewayDeployment:
|
||||
Type: AWS::ApiGateway::Deployment
|
||||
DependsOn: ApiGatewayMethod
|
||||
Properties:
|
||||
RestApiId: !Ref ApiGatewayRestApi
|
||||
StageName: prod
|
||||
|
||||
Outputs:
|
||||
ApiEndpoint:
|
||||
Description: "Endpoint URL for POST /invoke"
|
||||
Value: !Sub "https://${ApiGatewayRestApi}.execute-api.${AWS::Region}.amazonaws.com/prod/invoke"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user