Build your first application with Infrastructure Composer - AWS Infrastructure Composer

Build your first application with Infrastructure Composer

In this tutorial, you use AWS Infrastructure Composer to build a create, read, update, and delete (CRUD) serverless application that manages users in a database.

For this tutorial, we use Infrastructure Composer in the AWS Management Console. We recommend that you use Google Chrome or Microsoft Edge, and a full-screen browser window.

Are you new to serverless?

Resource properties reference

While building your application, use this table for reference to configure the properties of your Amazon API Gateway and AWS Lambda resources.

Method Path Function name

GET

/items

getItems

GET

/items/{id}

getItem

PUT

/items/{id}

updateItem

POST

/item

addItem

DELETE

/items/{id}

deleteItem

Step 1: Create your project

To get started with your CRUD serverless application, create a new project in Infrastructure Composer and activate local sync.

To create a new blank project
  1. Sign in to the Infrastructure Composer console.

  2. On the Home page, choose Create project.

As shown in the following image, Infrastructure Composer opens the visual canvas and loads a starting (blank) application template.

Infrastructure Composer with a blank visual canvas.
To activate local sync
  1. From the Infrastructure Composer menu, select Save > Activate local sync.

    An Infrastructure Composer menu with Activate local sync selected.
  2. For Project location, press Select folder and choose a directory. This is where Infrastructure Composer will save and sync your template files and folders as you design.

    The project location must not contain an existing application template.

    Note

    Local sync requires a browser that supports the File System Access API. For more information, see Data Infrastructure Composer gains access to.

  3. When prompted to allow access, select View files.

  4. Press Activate to turn on local sync. When prompted to save changes, select Save changes.

    When activated, the Autosave indicator will be displayed in the upper-left area of your canvas.

Step 2: Add cards to the canvas

Start to design your application architecture using enhanced component cards, beginning with an API Gateway REST API and five Lambda functions.

To add API Gateway and Lambda cards to the canvas

From the Resources palette, under the Enhanced components section, do the following:

  1. Drag an API Gateway card onto the canvas.

  2. Drag a Lambda Function card onto the canvas. Repeat until you've added five Lambda Function cards to the canvas.

An Infrastructure Composer canvas view with one API Gateway and five Lambda Function cards.

Step 3: Configure your API Gateway REST API

Next, add five routes within your API Gateway card.

To add routes to the API Gateway card
  1. Open the Resource properties panel for the API Gateway card. To open the panel, double-click the card. Or, select the card, and then choose Details.

  2. In the Resource properties panel, under Routes, do the following:

    Note

    For each of the following routes, use the HTTP method and path values specified in the resource properties reference table.

    1. For Method, choose the specified HTTP method. For example, GET.

    2. For Path, enter the specified path. For example, /items.

    3. Choose Add route.

    4. Repeat the previous steps until you've added all five specified routes.

  3. Choose Save.

The Infrastructure Composer visual canvas with an API Gateway resource with five routes. The Resource properties panel shows selections for Method, Path, and Add route.

Step 4: Configure your Lambda functions

Name each of the five Lambda functions as specified in the resource properties reference table.

To name the Lambda functions
  1. Open the Resource properties panel of a Lambda Function card. To open the panel, double-click the card. Or, select the card, and then choose Details.

  2. In the Resource properties panel, for Logical ID, enter a specified function name. For example, getItems.

  3. Choose Save.

  4. Repeat the previous steps until you've named all five functions.

The Infrastructure Composer visual canvas with five named Lambda Function resource cards.

Step 5: Connect your cards

Connect each route on your API Gateway card to its related Lambda Function card, as specified in the resource properties reference table.

To connect your cards
  1. Click a right port on the API Gateway card and drag it to the left port of the specified Lambda Function card. For example, click the GET /items port and drag it to the left port of getItems.

  2. Repeat the previous step until you've connected all five routes on the API Gateway card to corresponding Lambda Function cards.

The Infrastructure Composer visual canvas with the REST API connected to five Lambda functions.

Step 6: Organize the canvas

Organize the visual canvas by grouping together your Lambda functions and arranging all the cards.

To group together your functions
  1. Press and hold Shift, then select each Lambda Function card on the canvas.

  2. Choose Group.

To name your group
  1. Double-click the top of the group, near the group name (Group).

    The Group properties panel opens.

  2. On the Group properties panel, for Group name, enter API.

  3. Choose Save.

To arrange your cards

On the canvas, above the main view area, choose Arrange.

Infrastructure Composer arranges and aligns all cards on the visual canvas, including your new group (API), as shown here:

The Infrastructure Composer visual canvas arranged with all Lambda functions grouped together.

Step 7: Add and connect a DynamoDB table

Now, add a DynamoDB table to your application architecture and connect it to your Lambda functions.

To add and connect a DynamoDB table
  1. From the resource palette (Resources), under the Enhanced components section, drag a DynamoDB Table card onto the canvas.

  2. Click the right port on a Lambda Function card and drag it to the left port of the DynamoDB Table card.

  3. Repeat the previous step until you've connected all five Lambda Function cards to the DynamoDB Table card.

  4. (Optional) To reorganize and realign the cards on the canvas, choose Arrange.

The Infrastructure Composer visual canvas with a DynamoDB table connected to the group API.

Step 8: Review your AWS CloudFormation template

Congratulations! You've successfully designed a serverless application that's ready for deployment. Finally, choose Template to review the AWS CloudFormation template that Infrastructure Composer has automatically generated for you.

In the template, Infrastructure Composer has defined the following:

  • The Transform declaration, which specifies the template as an AWS Serverless Application Model (AWS SAM) template. For more information, see AWS SAM template anatomy in the AWS Serverless Application Model Developer Guide.

  • An AWS::Serverless::Api resource, which specifies your API Gateway REST API with its five routes.

  • Five AWS::Serverless::Function resources, which specify your Lambda functions' configurations, including their environment variables and permissions policies.

  • An AWS::DynamoDB::Table resource, which specifies your DynamoDB table and its properties.

  • The Metadata section, which contains information about your resource group (API). For more information about this section, see Metadata in the AWS CloudFormation User Guide.

The Infrastructure Composer template view showing the application's template code.

Step 9: Integrate into your development workflows

Use the template file and project directories that Infrastructure Composer created for further testing and deployment.

Next steps

You're now ready to build your own applications with Infrastructure Composer. For in-depth details on using Infrastructure Composer, refer to How to compose in AWS Infrastructure Composer. When you are ready to deploy your application, refer to Deploy your Infrastructure Composer serverless application to the AWS Cloud.