|
| 1 | +service: StepFuncBatch |
| 2 | + |
| 3 | +frameworkVersion: ">=1.2.0 <2.0.0" |
| 4 | + |
| 5 | +provider: |
| 6 | + name: aws |
| 7 | + region: us-east-1 |
| 8 | + runtime: python3.6 |
| 9 | + memorySize: 128 |
| 10 | + timeout: 10 |
| 11 | + |
| 12 | +package: |
| 13 | + exclude: |
| 14 | + - node_modules/** |
| 15 | + |
| 16 | +functions: |
| 17 | + branch: |
| 18 | + handler: index.handlerBranch |
| 19 | + map: |
| 20 | + handler: index.handlerMap |
| 21 | + reduce: |
| 22 | + handler: index.handlerReduce |
| 23 | + |
| 24 | + |
| 25 | +stepFunctions: |
| 26 | + stateMachines: |
| 27 | + HelloWorldStepFunction: |
| 28 | + events: |
| 29 | + - http: |
| 30 | + path: startFunction |
| 31 | + method: GET |
| 32 | + name: ${self:service}-StepFunction |
| 33 | + definition: |
| 34 | + StartAt: StartStepF |
| 35 | + States: |
| 36 | + StartStepF: |
| 37 | + Type: Task |
| 38 | + Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-map |
| 39 | + Next: BatchStep |
| 40 | + BatchStep: |
| 41 | + Type: Task |
| 42 | + Resource: arn:aws:states:::batch:submitJob.sync |
| 43 | + Parameters: |
| 44 | + JobName: TestStep |
| 45 | + JobDefinition: "#{JobDefinition}" |
| 46 | + JobQueue: "#{JobQueue}" |
| 47 | + ContainerOverrides: |
| 48 | + Command: |
| 49 | + - 'app/exec' |
| 50 | + Next: Parallel |
| 51 | + Parallel: |
| 52 | + Type: Parallel |
| 53 | + Next: EndStepF |
| 54 | + Branches: |
| 55 | + - StartAt: Branch1 |
| 56 | + States: |
| 57 | + Branch1: |
| 58 | + Type: Task |
| 59 | + Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-branch |
| 60 | + End: True |
| 61 | + - StartAt: Branch2 |
| 62 | + States: |
| 63 | + Branch2: |
| 64 | + Type: Task |
| 65 | + Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-branch |
| 66 | + End: True |
| 67 | + EndStepF: |
| 68 | + Type: Task |
| 69 | + Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-reduce |
| 70 | + End: true |
| 71 | + |
| 72 | +plugins: |
| 73 | + - serverless-step-functions |
| 74 | + - serverless-pseudo-parameters |
| 75 | + |
| 76 | +resources: |
| 77 | + Parameters: |
| 78 | + ImageUrl: |
| 79 | + Type: String |
| 80 | + Default: stepfunctiontest:latest |
| 81 | + Description: The url of a docker image that contains the application process that |
| 82 | + will handle the traffic for this service |
| 83 | + Resources: |
| 84 | + ComputeEnvironment: |
| 85 | + Type: AWS::Batch::ComputeEnvironment |
| 86 | + Properties: |
| 87 | + Type: MANAGED |
| 88 | + ServiceRole: arn:aws:iam::#{AWS::AccountId}:role/service-role/AWSBatchServiceRole |
| 89 | + ComputeEnvironmentName: '#{AWS::StackName}-ComputeEnvironment' |
| 90 | + ComputeResources: |
| 91 | + MaxvCpus: 128 |
| 92 | + SecurityGroupIds: |
| 93 | + - !Ref BatchSecurityGroup |
| 94 | + Type: SPOT |
| 95 | + SpotIamFleetRole: arn:aws:iam::#{AWS::AccountId}:role/aws-ec2-spot-fleet-tagging-role |
| 96 | + Subnets: |
| 97 | + - !Ref PublicSubnet1 |
| 98 | + MinvCpus: 0 |
| 99 | + InstanceRole: ecsInstanceRole |
| 100 | + InstanceTypes: |
| 101 | + - c5.large |
| 102 | + Tags: {"Name": "Batch Instance - #{AWS::StackName}"} |
| 103 | + DesiredvCpus: 0 |
| 104 | + State: ENABLED |
| 105 | + JobQueue: |
| 106 | + Type: AWS::Batch::JobQueue |
| 107 | + Properties: |
| 108 | + ComputeEnvironmentOrder: |
| 109 | + - Order: 1 |
| 110 | + ComputeEnvironment: !Ref ComputeEnvironment |
| 111 | + State: ENABLED |
| 112 | + Priority: 1 |
| 113 | + JobQueueName: '#{AWS::StackName}-JobQueue' |
| 114 | + JobDefinition: |
| 115 | + Type: "AWS::Batch::JobDefinition" |
| 116 | + Properties: |
| 117 | + Type: Container |
| 118 | + ContainerProperties: |
| 119 | + Command: |
| 120 | + - ls |
| 121 | + Memory: 128 |
| 122 | + Vcpus: 1 |
| 123 | + Image: '#{AWS::AccountId}.dkr.ecr.#{AWS::Region}.amazonaws.com/#{ImageUrl}' |
| 124 | + JobDefinitionName: '#{AWS::StackName}-JobDefinition' |
| 125 | + RetryStrategy: |
| 126 | + Attempts: 1 |
| 127 | + PubPrivateVPC: |
| 128 | + Type: 'AWS::EC2::VPC' |
| 129 | + Properties: |
| 130 | + CidrBlock: 172.31.0.0/16 |
| 131 | + Tags: |
| 132 | + - Key: Name |
| 133 | + Value: !Join [_, [!Ref 'AWS::StackName']] |
| 134 | + PublicSubnet1: |
| 135 | + Type: 'AWS::EC2::Subnet' |
| 136 | + Properties: |
| 137 | + VpcId: !Ref PubPrivateVPC |
| 138 | + AvailabilityZone: '#{AWS::Region}a' |
| 139 | + CidrBlock: 172.31.48.0/20 |
| 140 | + MapPublicIpOnLaunch: true |
| 141 | + InternetGateway: |
| 142 | + Type: 'AWS::EC2::InternetGateway' |
| 143 | + Properties: |
| 144 | + Tags: |
| 145 | + - Key: Name |
| 146 | + Value: !Join [_, [!Ref 'AWS::StackName']] |
| 147 | + - Key: Network |
| 148 | + Value: Public |
| 149 | + GatewayToInternet: |
| 150 | + Type: 'AWS::EC2::VPCGatewayAttachment' |
| 151 | + Properties: |
| 152 | + VpcId: !Ref PubPrivateVPC |
| 153 | + InternetGatewayId: !Ref InternetGateway |
| 154 | + PublicRouteTable: |
| 155 | + Type: 'AWS::EC2::RouteTable' |
| 156 | + Properties: |
| 157 | + VpcId: !Ref PubPrivateVPC |
| 158 | + Tags: |
| 159 | + - Key: Network |
| 160 | + Value: Public |
| 161 | + PublicRoute: |
| 162 | + Type: 'AWS::EC2::Route' |
| 163 | + DependsOn: GatewayToInternet |
| 164 | + Properties: |
| 165 | + RouteTableId: !Ref PublicRouteTable |
| 166 | + DestinationCidrBlock: 0.0.0.0/0 |
| 167 | + GatewayId: !Ref InternetGateway |
| 168 | + PublicSubnet1RouteTableAssociation: |
| 169 | + Type: 'AWS::EC2::SubnetRouteTableAssociation' |
| 170 | + Properties: |
| 171 | + SubnetId: !Ref PublicSubnet1 |
| 172 | + RouteTableId: !Ref PublicRouteTable |
| 173 | + NatGateway: |
| 174 | + Type: "AWS::EC2::NatGateway" |
| 175 | + DependsOn: NatPublicIP |
| 176 | + Properties: |
| 177 | + AllocationId: !GetAtt NatPublicIP.AllocationId |
| 178 | + SubnetId: !Ref PublicSubnet1 |
| 179 | + NatPublicIP: |
| 180 | + Type: "AWS::EC2::EIP" |
| 181 | + DependsOn: PubPrivateVPC |
| 182 | + Properties: |
| 183 | + Domain: vpc |
| 184 | + BatchSecurityGroup: |
| 185 | + Type: AWS::EC2::SecurityGroup |
| 186 | + Properties: |
| 187 | + GroupDescription: Allow all ports |
| 188 | + VpcId: |
| 189 | + Ref: PubPrivateVPC |
0 commit comments