{"id":27786285,"url":"https://github.com/clever/sfncli","last_synced_at":"2025-04-30T15:59:01.981Z","repository":{"id":25353395,"uuid":"103795523","full_name":"Clever/sfncli","owner":"Clever","description":"Utility to create AWS Step Function activities out of command line programs","archived":false,"fork":false,"pushed_at":"2025-04-24T19:12:51.000Z","size":186,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-24T20:26:38.004Z","etag":null,"topics":["aws","sfn","step-functions","workflow-management"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clever.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-17T01:46:10.000Z","updated_at":"2025-04-24T19:12:56.000Z","dependencies_parsed_at":"2022-07-24T20:32:04.416Z","dependency_job_id":"1ee843aa-9a59-406e-8ca7-23280311fb62","html_url":"https://github.com/Clever/sfncli","commit_stats":{"total_commits":156,"total_committers":22,"mean_commits":7.090909090909091,"dds":0.7051282051282051,"last_synced_commit":"01fa843553ce6963a1ac6dfee82f777419b06e1f"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fsfncli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fsfncli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fsfncli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fsfncli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clever","download_url":"https://codeload.github.com/Clever/sfncli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251737801,"owners_count":21635676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","sfn","step-functions","workflow-management"],"created_at":"2025-04-30T15:59:01.255Z","updated_at":"2025-04-30T15:59:01.970Z","avatar_url":"https://github.com/Clever.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sfncli\n\nUtility to create AWS Step Function (SFN) activities out of command line programs.\n\n## Usage\n\n```\n$ sfncli -h\nUsage of sfncli:\n  -activityname string\n    \tThe activity name to register with AWS Step Functions. $VAR and ${VAR} env variables are expanded.\n  -cmd string\n    \tThe command to run to process activity tasks.\n  -region string\n    \tThe AWS region to send Step Function API calls. Defaults to AWS_REGION.\n  -cloudwatchregion string\n      The AWS region to send metric data. Defaults to the value of region.\n  -version\n    \tPrint the version and exit.\n  -workername string\n    \tThe worker name to send to AWS Step Functions when processing a task. Environment variables are expanded. The magic string MAGIC_ECS_TASK_ARN will be expanded to the ECS task ARN via the metadata service.\n  -workdirectory string\n    \tA directory path that is passed to the `cmd` using an env var `WORK_DIR`. For each activity task a new directory is created in `workdirectory` and it is cleaned up after the activity task exits. Defaults to \"\", does not create directory or set `WORK_DIR`\n```\n\nExample:\n\n```\nsfncli -activityname sleep-100 -region us-west-2 --cloudwatchregion us-west-1 -workername sleep-worker -cmd sleep 100\n```\n\n## High-level logic\n\n- On startup, call [`CreateActivity`](http://docs.aws.amazon.com/step-functions/latest/apireference/API_CreateActivity.html) to register an [Activity](http://docs.aws.amazon.com/step-functions/latest/dg/concepts-activities.html) with Step Functions.\n- Begin polling [`GetActivityTask`](http://docs.aws.amazon.com/step-functions/latest/apireference/API_GetActivityTask.html) for tasks.\n- Get a task. Take the JSON input for the task and\n  - if it's a JSON object, use this as the last arg to the `cmd` passed to `sfncli`.\n  - if it's anything else (e.g. JSON array), an error is thrown.\n  - if `_EXECUTION_NAME` is missing from the payload, an error is thrown\n  - the `_EXECUTION_NAME` payload attribute value is added to the environment of the `cmd` as `_EXECUTION_NAME`.\n  - if workdirectory is set, create a sub-directory and add it to the environment of the `cmd` as `WORK_DIR`.\n- Start [`SendTaskHeartbeat`](http://docs.aws.amazon.com/step-functions/latest/apireference/API_SendTaskHeartbeat.html) loop.\n- When the command exits:\n  - Call [`SendTaskFailure`](http://docs.aws.amazon.com/step-functions/latest/apireference/API_SendTaskFailure.html) if it exited nonzero, was killed, or `sfncli` received SIGTERM.\n  - Call [`SendTaskSuccess`](http://docs.aws.amazon.com/step-functions/latest/apireference/API_SendTaskSuccess.html) otherwise.\n    Parse the last line of the `stdout` of the command as the output for the task (it [must be JSON](https://states-language.net/spec.html#data)).\n  - If `workdirectory` was set then cleanup `WORK_DIR`/sub-directory-for-task\n\n## Errors\n\n[Error names](https://states-language.net/spec.html#error-names) in SFN state machines are useful for debugging and setting up branching/retry logic in state machine definitions.\n`sfncli` will report the following error names if it encounters errors it can identify:\n\n- `sfncli.TaskInputNotJSON`: input to the task was not JSON\n- `sfncli.TaskFailureTaskInputMissingExecutionName`: input is missing `_EXECUTION_NAME` attribute\n- `sfncli.CommandNotFound`: the command passed to `sfncli` was not found\n- `sfncli.CommandKilled`: the command process received SIGKILL\n- `sfncli.CommandExitedNonzero`: the command process exited with a nonzero exit code\n- `sfncli.TaskOutputNotJSON`: the task output (last line of command's `stdout`) was not JSON\n- `sfncli.CommandTerminated`: `sfncli` or the command received SIGTERM\n- `sfncli.Unknown`: unexpected / unclassified errors\n\nThe command should signal an error by exiting with a nonzero status code. In this case, the behavior is:\n1. If the last line of *stdout* was a JSON-formatted string with an `error` field, report an error to Step Functions with that field as the name and the value of the `cause` field in the output line as the cause.\n2. Otherwise, report an error with name `sfncli.CommandExitedNonzero` with the last line of *stderr* as the cause.\n\n## Local testing\n\nStart up a test activity that runs `echo` on the work it receives.\n\n```\ngo run ./cmd/sfncli -region us-west-2 -activityname test-activity -workername sfncli-test -cmd echo\n```\n\nCreate a new state machine that uses this activity for one of its states (this requires you to [create a role for use with Step Functions](http://docs.aws.amazon.com/step-functions/latest/dg/procedure-create-iam-role.html)):\n\n```\naws --region us-west-2 stepfunctions create-state-machine --name test-state-machine --role-arn arn:aws:iam::589690932525:role/raf-test-step-functions --definition '{\n    \"Comment\": \"Testing out step functions\",\n    \"StartAt\": \"foo\",\n    \"Version\": \"1.0\",\n    \"TimeoutSeconds\": 60,\n    \"States\": {\n        \"foo\": {\n            \"Resource\": \"arn:aws:states:us-west-2:589690932525:activity:test-activity\",\n            \"Type\": \"Task\",\n            \"End\": true\n        }\n    }\n}'\n```\n\nNote that you will need to replace the `Resource` above to reflect the correct ARN with your AWS account ID.\n\nStart an execution of the state machine (again replacing the ARN below with the correct account ID):\n\n```\naws --region us-west-2 stepfunctions start-execution --state-machine-arn arn:aws:states:us-west-2:589690932525:stateMachine:test-state-machine  --input '{\"_EXECUTION_NAME\":\"en\", \"hello\": \"world\"}'\n```\n\nYou should see `echo` run with the argument `{\"hello\": \"world\"}`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclever%2Fsfncli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclever%2Fsfncli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclever%2Fsfncli/lists"}