[{"data":1,"prerenderedAt":99},["ShallowReactive",2],{"content-svc-step-functions-guides-integrating-step-functions-with-containerized-workloads-70-activity":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":21,"menu":22,"menuType":96,"isCollapseableMenu":25,"nextDocItem":91,"previousDocItem":69,"contributorPaths":97,"contentName":24,"slug":90,"readingTime":41},"\u003Cp>Activities are a Step Functions feature that enables you to process messages in an external worker running in Amazon EKS task, on-premise servers etc. As activities act as queue between the Step Functions workflow and the external system, they offer a highly scalable, resilient and asynchronous mechanism to connect your services running in Amazon ECS tasks, Amazon EKS pods or basically anywhere. You can use Step Functions activity metrics such as ActivitiesScheduled and ActivitiesStarted to scale in\u002Fscale out the workers.\u003C\u002Fp>\n\u003Cp>To get started with activities, you create an activity in Step Functions console, API, CLI or in a workflow. You then use the activity state in the workflow to send the task to the activities. The data waits in the activity until it is consumed by the worker. Here is a sample code for worker to consume task from Step Functions activity.\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">\nclient = boto3.client(&#39;stepfunctions&#39;, region_name=region, config=config)\nactivity = client.get_activity_task(\n    activityArn = activity_arn,\n    workerName = worker_name\n  )\n\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Worker receives tasktoken and the task input. Once the worker completes the processing, it sends the success or failure back to Step Functions. This mechanism works very similar to \u003Ccode>Wait for a Callback\u003C\u002Fcode> integration.\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002Fassets\u002Factivtytoken.png\" alt=\"image\">\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-python\">if success:\n  client.send_task_success(\n    taskToken = activity[&#39;taskToken&#39;],\n    output = stringoutput\n  )\nelse:\n  client.send_task_failure(\n    taskToken = activity[&#39;taskToken&#39;],\n    cause = strCause,\n    error = strError\n  )\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Advantages of Activity integration\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Col>\n\u003Cli>Activities can be used with any compute environment as long as the compute environment can assume an IAM role and call the Step Functions API.\u003C\u002Fli>\n\u003Cli>Activties are an advantage when using with Amazon ECS when you want to send more than 8KB of data to ECS tasks. Activity has a max payload size of 256KB.\u003C\u002Fli>\n\u003Cli>Activties offer additional layer of resiliency as they can act as buffers between your workflow and the worker. This is very useful when you have a low scaling worker. The task remains in the activity queue and the workflow waits until the task is consumed. If the worker dies for any reason before processing the task, the task will reappear in the activity after the elapesed time.\u003C\u002Fli>\n\u003C\u002Fol>\n",{"title":6,"order":7,"resources":8,"callout":17},"Activity Integration",70,[9,13],{"link":10,"text":11,"type":12},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fconcepts-activities.html","Activities","documentation",{"link":14,"text":15,"type":16},"https:\u002F\u002Fcatalog.us-east-1.prod.workshops.aws\u002Fworkshops\u002F2a22e604-2f2e-4d7b-85a8-33b38c999234\u002Fen-US\u002Fuse-cases\u002Fmonte-carlo-simulation","Run Monte Carlo Simulation with AWS Fargate and Step Functions Activity","workshop",{"title":18,"description":19,"link":20},"Using Activities with AWS Fargate","This blog post demostrates how you can use Activities with AWS Fargate at scale.","https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcontainers\u002Frun-monte-carlo-simulations-at-scale-with-aws-step-functions-and-aws-fargate\u002F","Activities are a Step Functions feature that enables you to process messages in an external worker running in Amazon EKS task, on-premise servers etc. As activities act as queue between the Step Functions workflow and the external system, they offer a highly scalable, resilient and asynchronous mechanism to connect your services running in Amazon ECS tasks, Amazon EKS pods or basically anywhere. You can use Step Functions activity metrics such as ActivitiesScheduled and ActivitiesStarted to scale in\u002Fscale out the workers.\n\n\nTo get started with activities, you create an activity in Step Functions console, API, CLI or in a workflow. You then use the activity state in the workflow to send the task to the activities. The data waits in the activity until it is consumed by the worker. Here is a sample code for worker to consume task from Step Functions activity.\n\n\n```python\n\nclient = boto3.client('stepfunctions', region_name=region, config=config)\nactivity = client.get_activity_task(\n    activityArn = activity_arn,\n    workerName = worker_name\n  )\n\n\n```\nWorker receives tasktoken and the task input. Once the worker completes the processing, it sends the success or failure back to Step Functions. This mechanism works very similar to `Wait for a Callback` integration.\n\n![image](\u002Fassets\u002Fexternal\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002Fassets\u002Factivtytoken.png)\n\n```python\nif success:\n  client.send_task_success(\n    taskToken = activity['taskToken'],\n    output = stringoutput\n  )\nelse:\n  client.send_task_failure(\n    taskToken = activity['taskToken'],\n    cause = strCause,\n    error = strError\n  )\n\n```\n**Advantages of Activity integration**\n\n1. Activities can be used with any compute environment as long as the compute environment can assume an IAM role and call the Step Functions API.\n2. Activties are an advantage when using with Amazon ECS when you want to send more than 8KB of data to ECS tasks. Activity has a max payload size of 256KB.\n3. Activties offer additional layer of resiliency as they can act as buffers between your workflow and the worker. This is very useful when you have a low scaling worker. The task remains in the activity queue and the workflow waits until the task is consumed. If the worker dies for any reason before processing the task, the task will reappear in the activity after the elapesed time.\n\n\n",[23],{"title":24,"collapsible":25,"isCollapsed":25,"content":26},"Integrating Step Functions with containerized workloads",false,[27,34,45,56,69,83,91],{"title":28,"order":29,"time":30,"path":31,"id":32,"link":33},"Introduction",10,"1 min","10-introduction","10-introduction.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F10-introduction",{"title":35,"order":36,"resources":37,"time":41,"path":42,"id":43,"link":44},"Service Integration patterns and AWS service integrations ",20,[38],{"link":39,"text":40,"type":12},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fconnect-to-resource.html","Service integration patterns","2 min","20-patterns","20-patterns.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F20-patterns",{"title":46,"order":47,"resources":48,"time":30,"path":53,"id":54,"link":55},"Connecting to systems outside AWS",40,[49,52],{"link":50,"text":51,"type":12},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fconnect-third-party-apis.html","Third party API integration",{"link":10,"text":6,"type":12},"40-external-system-integration","40-external-system-integration.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F40-external-system-integration",{"title":57,"order":58,"resources":59,"time":41,"path":66,"id":67,"link":68},"Run a job Integration",50,[60,63],{"link":61,"text":62,"type":12},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fconnect-ecs.html","Manage Amazon ECS or Fargate Tasks with Step Functions",{"link":64,"text":65,"type":12},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fconnect-eks.html","Call Amazon EKS with Step Functions","50-run-a-job","50-run-a-job.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F50-run-a-job",{"title":70,"order":71,"callout":72,"resources":75,"time":41,"path":80,"id":81,"link":82},"Wait for Callback integration",60,{"title":73,"description":73,"link":74},"Parallel video processing using AWS Fargate tasks","https:\u002F\u002Fcatalog.workshops.aws\u002Fstepfunctions\u002Fen-US\u002Fuse-cases\u002Fdata-processing\u002Fmap-ecs",[76],{"link":77,"text":78,"type":79},"https:\u002F\u002Fserverlessland.com\u002Fpatterns\u002Fsfn-ecs-sam","Sample pattern for Wait for Callback","pattern","60-callback","60-callback.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F60-callback",{"title":6,"order":7,"resources":84,"callout":87,"time":41,"path":88,"id":89,"link":90},[85,86],{"link":10,"text":11,"type":12},{"link":14,"text":15,"type":16},{"title":18,"description":19,"link":20},"70-activity","70-activity.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F70-activity",{"title":92,"order":29,"time":30,"path":93,"id":94,"link":95},"Conclusion","80-conclusion","80-conclusion.md","\u002Fcontent\u002Fservice\u002Fstep-functions\u002Fguides\u002Fintegrating-step-functions-with-containerized-workloads\u002F80-conclusion","LIST",[98],"content\u002Fcontributors\u002Fuma-ramadoss.json",1792578874835]