AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: > A Step Functions Standard Workflow that invokes a Lambda function via a API Gateway REST APIs integration Resources: ########################################################################## # STEP FUNCTION # ########################################################################## StateMachinetoAPIGW: Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html Properties: DefinitionUri: statemachine/stateMachine.asl.json DefinitionSubstitutions: DefaultPath: '/' APIEndPoint: !Sub "${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com" Role: Fn::GetAtt: [ StatesExecutionRole, Arn ] Logging: Destinations: - CloudWatchLogsLogGroup: LogGroupArn: !GetAtt StateMachineLogGroup.Arn IncludeExecutionData: false Level: 'ALL' ########################################################################## # Lambda function # ########################################################################## ExampleLambdaFunction: Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html Properties: CodeUri: src Handler: app.handler Runtime: nodejs12.x Events: Api: Type: Api Properties: Path: / Method: GET ########################################################################## # STEP FUNCTION LOG GROUP # ########################################################################## StateMachineLogGroup: Type: AWS::Logs::LogGroup Properties: LogGroupName: !Join [ "/", [ "stepfunctions", StateMachinetoAPIGW]] ########################################################################## # Roles # ########################################################################## StatesExecutionRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: "Allow" Principal: Service: - !Sub states.${AWS::Region}.amazonaws.com Action: "sts:AssumeRole" Path: "/" Policies: - PolicyName: LambdaExecute PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - "lambda:InvokeFunction" Resource: !GetAtt ExampleLambdaFunction.Arn - PolicyName: LogPermissions PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - "cloudwatch:*" - "logs:*" Resource: "*" ########################################################################## # Outputs # ########################################################################## Outputs: StateMachinetoAPIGW: Value: !Ref StateMachinetoAPIGW Description: StateMachinetoAPIGW Arn WebEndpoint: Description: "API Gateway endpoint URL for Prod stage" Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"