ServiceName:
Description: Name to be used for the EventBridge Bus and API Gateway, i.e. some-service-name
Type: String
Resources:
EventBus:
Type: AWS::Events::EventBus
Properties:
Name: !Ref ServiceName
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
openapi: "3.0.1"
info:
title: !Ref ServiceName
version: "2020-05-20T19:05:35Z"
paths:
/:
post:
responses:
"200":
description: "200 response"
content:
application/json:
schema:
$ref: "#/components/schemas/Empty"
x-amazon-apigateway-integration:
credentials: !GetAtt APIGatewayRole.Arn
uri: "arn:aws:apigateway:us-west-2:events:action/PutEvents"
responses:
default:
statusCode: "200"
requestParameters:
integration.request.header.X-Amz-Target: "'AWSEvents.PutEvents'"
integration.request.header.Content-Type: "'application/x-amz-json-1.1'"
requestTemplates:
application/json:
Fn::Sub: |
{
"Entries": [
{
"DetailType": "Event Type",
"Source": "Event Source",
"EventBusName": "${ServiceName}",
"Detail": "$util.escapeJavaScript($input.json('$'))"
}
]
}
passthroughBehavior: "when_no_templates"
httpMethod: "ANY"
type: "aws"
components:
schemas:
Empty:
title: "Empty Schema"
type: "object"
APIGatewayRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${ServiceName}-apigateway-role"
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: EventBridgeAccess
PolicyDocument:
Statement:
- Effect: Allow
Action:
- events:PutEvents
Resource: '*'
EventBusCatchallLogGroup:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName: !Sub "/aws/events/${ServiceName}"
RetentionInDays: 3
CatchallRule:
Type: AWS::Events::Rule
Properties:
Description: "Default Catch-All EventRule"
EventBusName: !Ref EventBus
EventPattern:
account:
- !Ref AWS::AccountId
State: "ENABLED"
Targets:
- Arn: !GetAtt EventBusCatchallLogGroup.Arn
Id: !Sub "${ServiceName}-log-group"
Outputs:
RESTEndpoint:
Value: !Sub "https://${ApiGatewayApi}.execute-api.us-west-2.amazonaws.com/prod/"
Export:
Name: !Sub "${AWS::StackName}-rest-endpoint"
Parameters
These are the input parameters for this template. All of these parameters must be supplied for this template to be deployed.