AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Description: > sfn-apigw-example Sample SAM Template for sfn-apigw-example Parameters: BuyPath: Type: String Default: /buy SellPath: Type: String Default: /sell CheckPath: Type: String Default: /check Resources: StockTradingStateMachine: 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/stock_trader.asl.json DefinitionSubstitutions: StockCheckPath: !Ref CheckPath StockSellPath: !Ref SellPath StockBuyPath: !Ref BuyPath APIEndPoint: !Sub "${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com" DDBPutItem: !Sub arn:${AWS::Partition}:states:::dynamodb:putItem DDBTable: !Ref TransactionTable Events: HourlyTradingSchedule: Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-schedule.html Properties: Description: Schedule to run the stock trading state machine every hour Enabled: False # This schedule is disabled by default to avoid incurring charges. Schedule: "rate(1 hour)" Policies: # Find out more about SAM policy templates: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html - LambdaInvokePolicy: FunctionName: !Ref StockCheckerFunction - LambdaInvokePolicy: FunctionName: !Ref StockSellerFunction - LambdaInvokePolicy: FunctionName: !Ref StockBuyerFunction - DynamoDBWritePolicy: TableName: !Ref TransactionTable StockCheckerFunction: 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: functions/stock-checker/ Handler: app.lambdaHandler Runtime: nodejs14.x Events: Api: Type: Api Properties: Path: /check Method: GET StockSellerFunction: Type: AWS::Serverless::Function Properties: CodeUri: functions/stock-seller/ Handler: app.lambdaHandler Runtime: nodejs14.x Events: Api: Type: Api Properties: Path: /sell Method: POST StockBuyerFunction: Type: AWS::Serverless::Function Properties: CodeUri: functions/stock-buyer/ Handler: app.lambdaHandler Runtime: nodejs14.x Events: Api: Type: Api Properties: Path: /buy Method: POST TransactionTable: Type: AWS::Serverless::SimpleTable # More info about SimpleTable Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-simpletable.html Properties: PrimaryKey: Name: Id Type: String ProvisionedThroughput: ReadCapacityUnits: 1 WriteCapacityUnits: 1 Outputs: # StockTradingStateMachineHourlyTradingSchedule is an implicit Schedule event rule created out of Events key under Serverless::StateMachine # Find out more about other implicit resources you can reference within SAM # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html StockTradingStateMachineArn: Description: "Stock Trading state machine ARN" Value: !Ref StockTradingStateMachine StockTradingStateMachineRole: Description: "IAM Role created for Stock Trading state machine based on the specified SAM Policy Templates" Value: !GetAtt StockTradingStateMachineRole.Arn WebEndpoint: Description: "API Gateway endpoint URL for Prod stage" Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"