Skip to content

Step 5. Create and deploy component

MACH composer is undergoing a major, backwards compatible overhaul

MACH composer has been rewritten in Golang, coming from a Python version. We've done this because the Golang ecosystem is more suitable for a tool like this, as it is also the language in which Hashicorp builds Terraform itself.

Because of this, some commands might not be available yet in the Golang version; particularly the mach-composer bootstrap command is not available, which makes it a bit harder to start up. However, based on the examples in the Github repository, you should be able to get started without the bootstrap command.

For creating components, please instead of mach-composer bootstrap component, use mach-composer-cookiecutter.

We do currently recommend to use the latest version (2.5.x).

If you are still on the Python version, the bootstrap command will still work.

1. Create a MACH component

Create a MACH component which we can use in our MACH stack later on.

$ mach-composer bootstrap component

And follow the wizard to create a new component.

Simple API component

We will be creating a simple API component that exposes 1 endpoint.

The bootstrapper will ask for some input to create the component, for the sake of this tutorial let's use the following values and replace your-project-lambdas with the S3 bucket name created in step 3.

Cloud environment (aws, azure) [aws]: aws
Language (python, node) [node]: node
Name [example-name]: api
Description [Api component]:
Directory name [api-component]:
Uses an HTTP endpoint? [Y/n]: y
Include GraphQL support? [Y/n]: y
Uses commercetools? [Y/n]: n
Use Sentry? [y/N]: n
Lambda repository S3 bucket: your-project-lambdas
New component api-component created 🎉

2. Initiate and test component

In the previous step we've created a Node component.

To install the environment and test it locally, run the following commands:

$ yarn
$ yarn test

Now that we've verified that the component works, we can deploy it to our component repository.

3. Deploy your component

It depends on what component you have, but if you've created a component containing a serverless function, that function needs to be built, packaged and uploaded to a component registry.


For a component created with the mach bootstrap command, the component can be packaged using;

$ ./ package


Now that we have our packaged component, we need to upload this to the component repository that we created in step 3.

Make sure that you're using the correct AWS profile to upload the ZIP file.

We can use the same role that we've used to perform the infra rollout. So make sure the following is added to your ~/.aws/config file:

[profile your-project-srv]
source_profile = default
role_arn = arn:aws:iam::<service-account-id>:role/admin

Using this AWS profile, we can upload the component.

$ ./ upload

Providing AWS credentials

To ensure the correct AWS profile is used you can set the AWS_DEFAULT_PROFILE environment variable.

The command will be AWS_DEFAULT_PROFILE=your-project-srv ./ upload.

We recommend using a solution like aws-vault:

aws-vault exec your-project-srv -- ./ upload

Another thing to note is that we are using role/admin here. Better would be to use the dedicated 'upload-role' that has been created using the terraform-aws-mach-shared module.
todo Describe how to set up these policies in a how-to article