Development Workflow
Following shows the stages or steps in developing, testing and debugging a topology using tc. Let’s assume the name of the sandbox is yoda and the AWS_PROFILE (provider environment) is dev.
-
Scaffold
Terminal window tc scaffold -
Compose
Terminal window tc compose -
Create
Terminal window tc create -s yoda -e dev -
Update
Terminal window tc update -s yoda -e devor update specific components for faster iteration
Terminal window tc update -s yoda -e dev -c ENTITYtc update -s yoda -e dev -c ENTITY/COMPONENTe.gtc update -s yoda -e dev -c routestc update -s yoda -e dev -c functions/vars -
List
Terminal window tc list -s yoda -e dev -
Invoke
Terminal window tc invoke -s yoda -e dev -p payload.jsontc invoke -s yoda -e dev -p s3://bucket/key.json -
Test
Terminal window tc test -s yoda -e dev [--recursive] -
Delete
Terminal window tc delete -s yoda -e dev [--recursive]
Scaffold
Section titled “Scaffold”- Define your events, routes, channels, queues, pages in topology.yml
routes: /api/foo: method: POST
events: MyEvent: producer: default
pages: myapp: dir: webapp- Specify how they are connected. For example
routes: /api/foo: method: POST authorizer: my-authorizer function: foo
events: MyEvent: producer: default function: bar
pages: myapp: dir: webapp- Additional scaffold the functions if they don’t exist, interactively.
tc scaffold --kind functionCompose
Section titled “Compose”We can now validate the entity definitions and their connections by running tc compose.
tc compose will generate a giant JSON that represents the target infrastructure (AWS Serverless by default).
You can see the generated permissions, target rules, mapping templates etc.
We can also have a tree view
tc compose -c functions -f treetc compose -s functions -f tabletc compose -c routes -f jsontc compose -c events -f jsontc compose -c states -f yamltc compose -c mutations -f graphqlBuilding Images
Section titled “Building Images”Most often, tc infers the kind of function, it’s runtime and how to build it. However, we can override the kind of build, for example Image or Inline. See Building Function Dependencies
tc buildTo build container images:
tc build --image base --publishtc build --image code --publishCreate Sandbox
Section titled “Create Sandbox”The following command create a sandbox in the given AWS profile (-e|—profile)
cd <topology-dir>tc create [--sandbox SANDBOX] [-e PROFILE]Update Sandbox
Section titled “Update Sandbox”While developing, we often need to incrementally deploy certain components without recreating the entire topology. tc provides an update command that updates given entity and components.
An entity is a core composable servereless resource. . A component is an attribute or instance of the entity.
We can update an entity and/or component as follows:
tc update -s SANDBOX -e PROFILE -c Entity/Componenttc update -s SANDBOX -e PROFILE -c routestc update -s SANDBOX -e PROFILE -c eventstc update -s SANDBOX -e PROFILE -c functionstc update -s SANDBOX -e PROFILE -c mutationstc update -s SANDBOX -e PROFILE -c channelstc update -s SANDBOX -e PROFILE -c schedulestc update -s SANDBOX -e PROFILE -c queuesTo update specific component in an entity:
Components in function entity:
tc update -s SANDBOX -e PROFILE -c functions/layerstc update -s SANDBOX -e PROFILE -c functions/varstc update -s SANDBOX -e PROFILE -c functions/concurrencytc update -s SANDBOX -e PROFILE -c functions/runtimetc update -s SANDBOX -e PROFILE -c functions/tagstc update -s SANDBOX -e PROFILE -c functions/rolestc update -s sandnox -e PROFILE -c functions/function-nameComponents in mutation entity:
tc update -s SANDBOX -e PROFILE -c mutations/authorizertc update -s SANDBOX -e PROFILE -c mutations/typestc update -s SANDBOX -e PROFILE -c mutations/rolestc update -s SANDBOX -e PROFILE -c mutations/RESOLVER_NAMEComponents in event entity:
tc update -s SANDBOX -e PROFILE -c events/EVENT_NAMEtc update -s SANDBOX -e PROFILE -c events/rolesComponents in route entity:
tc update -s SANDBOX -e PROFILE -c routes/ROUTE_NAMEtc update -s SANDBOX -e PROFILE -c routes/ROUTE_NAME/authorizertc update -s SANDBOX -e PROFILE -c routes/rolesList sandbox
Section titled “List sandbox”To list the entities in provisioned sandbox, do
tc list -s SANDBOX -e PROFILE [--format table|json]tc list -s SANDBOX -e PROFILE -c ENTITYInvoke
Section titled “Invoke”Payloads
Section titled “Payloads”By default, tc picks up a payload.json file in the current directory. You could optionally specify a payload file or an uri.
tc invoke -s SANDBOX -e PROFILE --payload payload.jsonor via stdin
cat payload.json | tc invoke -s SANDBOX -e PROFILEor as a param
tc invoke -s SANDBOX -e PROFILE --payload '{"data": "foo"}'or as s3 URI:
tc invoke -s SANDBOX -e PROFILE --payload s3://bucket/key.jsonInvoke specific entities
Section titled “Invoke specific entities”We can also invoke specify entity and/or component.
For example, to invoke a specific function in the topology:
tc invoke -s SANDBOX -e PROFILE -c functions/FUNCTION-NAME -p payload.jsonTo trigger/invoke a specific event. (Note the payload does not include detail-type or source of the event payload. It only has detail)
tc invoke -s SANDBOX -e PROFILE -c events/EVENT_NAME -p payload.jsonDelete Sandbox
Section titled “Delete Sandbox”To delete a sandbox:
tc delete -s sandbox -e envTo delete a specific entity/component. See update commands (above) for list of components
tc delete -s sandbox -e env -c ENTITY/COMPONENTOptionally, you way want to prune stale resources in your sandbox. tc does not maintain an external state to keep track of stale resources (those you delete locally but not in your sandbox).
tc prune -s SANDBOX -e PROFILE [--filter regexp]