Skip to content

Instantly share code, notes, and snippets.

@unknownliviu
Created January 8, 2019 17:36
Show Gist options
  • Save unknownliviu/c0459df2db27846e32548f7db672668c to your computer and use it in GitHub Desktop.
Save unknownliviu/c0459df2db27846e32548f7db672668c to your computer and use it in GitHub Desktop.
service:
name: zaius-data-test
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
provider:
name: aws
stage: ${opt:stage, 'sandbox'}
region: us-east-2
iamRoleStatements:
- Effect: "Allow"
Action:
- "ecs:CreateCluster"
- "ecs:ListServices"
- "ecs:ListContainerInstances"
- "ecs:ListTasks"
- "ecs:DescribeClusters"
- "ecs:DescribeServices"
- "ecs:DescribeTaskDefinition"
- "ecs:DescribeTasks"
- "ecs:DescribeContainerInstances"
- "ecs:CreateService"
- "ecs:DeleteService"
- "ecs:UpdateService"
- "ecs:StartTask"
- "ecs:RegisterTaskDefinition"
- "ecs:DeregisterTaskDefinition"
Resource:
- "*"
resources:
Resources:
EcsCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: user-api-test
EcsTask:
Type: AWS::ECS::TaskDefinition
Properties:
ExecutionRoleArn: ecsTaskExecutionRole
RequiresCompatibilities:
- FARGATE
Cpu: 512
Memory: 1024
NetworkMode: awsvpc
ContainerDefinitions:
-
Name: zaius-data-${self:provider.stage}
Command:
- /bin/sh
- "-c"
- "python events.py && python customers.py"
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: /ecs/zaius-data-${self:provider.stage}
awslogs-region: us-east-2
awslogs-stream-prefix: ecs
VolumesFrom: []
Image: "#{AWS::AccountId}.dkr.ecr.us-east-2.amazonaws.com/zaius-data:latest"
Essential: true
DisableNetworking: false
Environment:
-
Name: PROJECT_ENV
Value: ${self:provider.stage}
stepFunctions:
stateMachines:
zaiusDataMachine:
name: zaiusDataMachine
# role: "arn:aws:iam::#{AWS::AccountId}:role/itshouldwork"
events:
- schedule:
rate: rate(1 day)
name: "Daily Sync"
description: "Runs every 1 day"
- enabled: true
definition:
Comment: "A state machine"
StartAt: EcsZaius
States:
EcsZaius:
Type: Task
Resource: "arn:aws:states:::ecs:runTask.sync"
End: true
Parameters:
LaunchType: FARGATE
Cluster: "#{EcsCluster}"
TaskDefinition: "#{EcsTask}"
NetworkConfiguration:
AwsvpcConfiguration:
Subnets:
- subnet-b97383d0
- subnet-baa0abc2
AssignPublicIp: 'ENABLED'
# StateMachine:
# Type: "AWS::StepFunctions::StateMachine"
# Properties:
# StateMachineName: ZaiusDataMachine
# DefinitionString: |-
# {
# "StartAt":"EcsTest",
# "States":{
# "EcsTest": {
# "Type":"Task",
# "Resource":"arn:aws:states:::ecs:runTask.sync",
# "Parameters": {
# "LaunchType":"FARGATE",
# "Cluster": "Fn::GetAtt: [EcsCluster, Arn]",
# "TaskDefinition":
# - Ref: EcsTask
# },
# "End": true
# }
# }
# }
# RoleArn: { "Fn::Join" : ["", [ "arn:aws:iam::", { "Ref" : "AWS::AccountId" }, ":role/StepFunctionsLambdaRole" ] ] }
# TaskSchedule:
# Type: AWS::Events::Rule
# Properties:
# Name: Daily-Zaius-Sync
# Description: Schedules the task to be run every day at 1:00 am
# ScheduleExpression: rate(10 minutes)
# State: ENABLED
# Targets:
# -
# Id: zaius-data-daily-sync
# Arn:
# Fn::GetAtt:
# - EcsCluster
# - Arn
# RoleArn: { "Fn::Join" : ["", [ "arn:aws:iam::", { "Ref" : "AWS::AccountId" }, ":role/ecsTaskExecutionRole" ] ] }
# EcsParameters:
# TaskDefinitionArn:
# Ref: EcsTask
# TaskCount: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment