AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: API Gateway HTTP API to EventBridge Resources: # Creates an HTTP API endpoint MyHttpApi: Type: AWS::Serverless::HttpApi Properties: DefinitionBody: 'Fn::Transform': Name: 'AWS::Include' Parameters: Location: './api.yaml' # Create the role for API Gateway access to EventBridge MyHttpApiRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: "apigateway.amazonaws.com" Action: - "sts:AssumeRole" Policies: - PolicyName: ApiDirectWriteEventBridge PolicyDocument: Version: '2012-10-17' Statement: Action: - events:PutEvents Effect: Allow Resource: - !Sub arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/default # Lambda function invoked from EventBridge MyTriggeredLambda: Type: AWS::Serverless::Function Properties: CodeUri: src/ Handler: app.lambdaHandler Runtime: nodejs14.x Events: EventBridgeTrigger: Type: CloudWatchEvent Properties: Pattern: source: - "WebApp" Outputs: ApiEndpoint: Description: "HTTP API endpoint URL" Value: !Sub "https://${MyHttpApi}.execute-api.${AWS::Region}.amazonaws.com"