AWSTemplateFormatVersion: "2010-09-09" Description: (AWS Heidi) webhook stack for REST API Gateway to EventBridge Parameters: EventHealthBusArn: Type: String Description: EventHealthBusArn Resources: ApiGatewayEventBridgeRole: Type: AWS::IAM::Role Properties: RoleName: !Sub "EventHealthApiGW-${AWS::AccountId}-${AWS::Region}-Role" AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Sid: AllowApiGatewayServiceToAssumeRole Effect: Allow Action: - 'sts:AssumeRole' Principal: Service: - apigateway.amazonaws.com Policies: - PolicyName: EBPutEvents PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - 'events:PutEvents' Resource: - !Ref EventHealthBusArn apiGateway: Type: AWS::ApiGateway::RestApi Properties: EndpointConfiguration: Types: - REGIONAL Name: !Sub EventHealth-${AWS::AccountId}-${AWS::Region}-api apiGatewayRootMethod: Type: AWS::ApiGateway::Method Properties: AuthorizationType: NONE HttpMethod: POST MethodResponses: - StatusCode: 200 ResponseModels: application/json: Empty RequestParameters: method.request.header.X-Amz-Target: false method.request.header.Content-Type: false Integration: IntegrationHttpMethod: POST Type: AWS Credentials: !GetAtt ApiGatewayEventBridgeRole.Arn Uri: !Sub arn:aws:apigateway:${AWS::Region}:events:action/PutEvents PassthroughBehavior: WHEN_NO_TEMPLATES RequestTemplates: application/json: !Sub - |- #set($context.requestOverride.header.X-Amz-Target = "AWSEvents.PutEvents") #set($context.requestOverride.header.Content-Type = "application/x-amz-json-1.1") { "Entries": [ { "Detail": "$util.escapeJavaScript($input.json('$.Detail'))", "DetailType": "awshealthtest", "EventBusName": "default", "Source": $input.json('$.source') } ] } - EventBusName: !Select [1, !Split ["/", !Ref EventHealthBusArn]] IntegrationResponses: - StatusCode: 200 ResourceId: !GetAtt apiGateway.RootResourceId RestApiId: !Ref apiGateway apiGatewayDeployment: Type: AWS::ApiGateway::Deployment DependsOn: - apiGatewayRootMethod Properties: RestApiId: !Ref apiGateway StageName: 'v1' Outputs: ApiEndpoint: Description: "API Gateway endpoint URL for Prod stage for Product api" Value: !Sub "https://${apiGateway}.execute-api.${AWS::Region}.amazonaws.com/v1/"