Follow the step-by-step instructions below to create your REST API. Click on each step number to expand the section.

  • Step 1. Create a New RESTful API

    Amazon API Gateway enables you to create, publish, maintain, monitor, and secure your own REST and WebSocket API operations. Complete the following steps to create a new REST API.

    1. Open the Amazon API Gateway console at https://console.aws.amazon.com/apigateway.
    2. If this is your first API operation, choose Create new API. If this is a subsequent API operation, choose Create API.
    3. Under Choose the protocol, keep REST selected.
    4. Under Create new API, keep New API selected.
    5. Under Settings, do the following:
        • For API name, type examplecorp_si.
        • For Description, you can optionally type a description.
        • For Endpoint Type, choose Edge optimized.
    6. Choose Create API.
     

  • Step 2. Configure API Gateway for Lambda integration

    To configure API Gateway for Lambda integration, complete the following steps. The Lambda function that you create lets you share the AppStream 2.0 image with the AWS account of the requester.

    1. Open the Amazon API Gateway console at https://console.aws.amazon.com/apigateway.
    2. In the navigation pane, under the examplecorp_si API, choose Resources.
    3. Choose Actions, Create Resource.
    4. Do the following:
        • For Resource Name, type si.
        • For Resource Path, verify that the value is /si.
        • Select the Enable API Gateway CORS check box.
    5. Choose Create Resource.
    6. With your newly created resource (/si) selected in the Resources pane, choose Actions, Create Method.
    7. Under OPTIONS, choose POST, and select the check mark to the right of the list.
    8. In the POST Setup pane, do the following:
        • For Integration type, keep Lambda Function selected.
        • Select the Use Lambda Proxy integration check box.
        • For Lambda Region, verify that the Region where you created your Lambda function is selected.
        • For Lambda Function, type the name of the function that you created earlier in this project: examplecorp_lambda_si_function.
        • Choose Save.
    9. In the Add Permission to Lambda Function dialog box, choose OK.
    10. In the Resources pane, choose your resource, si.
    11. Choose Actions, Deploy API.
    12. In the Deploy API dialog box, do the following:
        • For Deployment stage, choose [New Stage].
        • For Stage name, type dev
        • For Stage description and Deployment description, you can optionally type a description.
        • Choose Deploy.
    13. At the top of the Stage Editor pane, the Invoke URL displays. Make a note of this URL. This URL is required later in the project.

  • Step 3. Update the web configuration files in your Amazon S3 bucket

    Update the as2.js file in your website deployment to include the invoke URL of the stage that you created. Complete the following steps to copy the invoke URL from the stage editor page in the API Gateway console and paste it into the invokeurl variable.

    1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.
    2. In the S3 buckets pane, in the search box, type the name of the Amazon S3 bucket that you created and where you copied the Example Corp. website files.
    3. When the bucket appears in the list, select the bucket name.
    4. On the Overview tab, in the file list, navigate to assets > js, select the check box next to the as2.js file, and choose Download.
    5. Navigate to the location where you downloaded this file on your local computer, and open the file.
    6. In the file, search for var invokeurl = to locate the invokeurl variable.
    7. Replace the default URL in this variable with the invoke URL that was generated when you completed the steps in “Configure API Gateway for Lambda integration.”
    8. Save your changes and close the file.
    9. On the Amazon S3 console Overview tab, choose Upload.
    10. Drag your edited as2.js file into the Upload window, and choose Upload.
    11. Wait for the upload to complete, and verify that the updated file appears in the list on the Overview tab.