Skip to main content

Perform Parallel Execution in AWS Step Functions

Hands-On Lab

 

Length

01:00:00

Difficulty

Intermediate

Step functions provide a powerful way to manage the execution of Lambda functions with a serverless pipeline. And we're not limited to running tasks sequentially. Step functions also allow us to run tasks in parallel. In this lab, we start with an existing step function definition and update it to include parallel execution of Lambda functions that both feed into the same single Lambda function as a final step. All the resources for this lab, including a sample audio file, can be found on GitHub: https://github.com/linuxacademy/content-aws-mls-c01/tree/master/Perform-Parallel-Execution-in-AWS-Step-Functions

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Perform Parallel Execution in AWS Step Functions

Introduction

Step functions provide a powerful way to manage the execution of Lambda functions with a serverless pipeline. And we're not limited to running tasks sequentially. Step functions also allow us to run tasks in parallel.

In this lab, we start with an existing step function definition and update it to include parallel execution of Lambda functions that both feed into the same single Lambda function as a final step.

All the resources for this lab, including a sample audio file, can be found on GitHub: https://github.com/linuxacademy/content-aws-mls-c01/tree/master/Perform-Parallel-Execution-in-AWS-Step-Functions

Scenario

We work for a company that holds meetings in English, with a management team that speaks Spanish. The management team wants an automated system that processes recordings of English meetings and translates them into Spanish. At the same time, the system should let the team know if the sentiment of the meeting was positive, negative, or neutral.

The videos walk through each of the steps, including navigating into the AWS console.

Please make sure to use the us-east-1 region when in the AWS console.

Connecting to the Lab

  1. Log in to the AWS Management Console using the credentials provided on the lab instructions page. Make sure you're using the us-east-1 region.

Update the Existing Step Functions to Include Parallel Execution

  1. Click Services in the top menu.

  2. Enter "step" in the search box and click Step Functions.

  3. Click Edit. Review the current function.

  4. Navigate to the GitHub project associated with this lab: https://github.com/linuxacademy/content-aws-mls-c01/tree/master/Perform-Parallel-Execution-in-AWS-Step-Functions

  5. Click lab-state-parallel.json.

  6. Select the entire contents of the file and copy them.

  7. Navigate back to the step function in the AWS Management Console. Select the following code (including the first comma but not including the bracket before the comma).

         ,
        "success": {
            "Type": "Pass",
            "End": true
        }, 
  8. Replace the selected text with the text copied from the JSON file in an earlier step.

  9. Click the refresh button on the right-hand side of the screen.

  1. Replace the following line

        "Next":"success"

    with

        "Next":"process-transcript"
  2. Click the refresh button on the right-hand side of the screen. Verify the layout of the step function.

Add Three Lambda Functions to the Step Functions Definition

  1. Click the Generate code snippet combo box.

  2. Enter "lambda" in the search box.

  3. Click AWS Lambda: Invoke a function.

  4. Under Lambda function, click the Select function combo box and select the function ending with "lab-trigger-comprehend-wrapper:$LATEST".

  5. Click Copy to clipboard.

  6. Select the following text in the step function.

            "comprehend":{
            "Type": "Pass",
            "End":true
            }
  7. Replace the selected text with the text in the clipboard.

  8. Replace

            "Invoke Lambda function": {

    with

            "comprehend": {
  9. Replace

            "Next": "NEXT_STATE"

    with

            "End": true
  1. At the top of the window, click Save.

  2. Click Save anyway.

  3. Select all the code between the line "comprehend": { and "End": true (but not including those lines). Copy that to the clipboard.

  4. Find the section of the step function that starts with "translate":{ and replace the next line ("Type": "Pass",) with the copied code.

  5. Replace lab-comprehend-wrapper with lab-translate-wrapper in the copied code.

  6. Find the section of the step function that starts with "polly":{ and replace the next line ("Type": "Pass",) with the copied code.

  7. Replace lab-comprehend-wrapper with lab-polly-wrapper in the copied code.

  8. At the top of the window, click Save.

  9. Click Save anyway.

Test the Step Function

  1. Click Services in the top menu.

  2. Enter "s3" in the search box and click S3.

  3. Click the link for the input bucket.

  4. Click Upload.

  5. Note: this step not in the lab video. Navigate back to the GitHub repository and click the folder to go up a level. Download the good-tea.m4a and bad-tea.m4a files.

  6. Drag the bad-tea.m4a file into the upload window.

  7. Click Upload.

  8. Click Services in the top menu.

  9. Enter "step" in the search box and right-click Step Functions to open it in a new tab.

  1. Navigate to the Step Functions tab.

  2. Click lab-step-functions.

  3. Click the link for the running execution of the step function in the Executions window.

  4. Once all steps are green, navigate back to the S3 console tab.

  5. Click Amazon S3.

  6. Click the link for the output bucket.

  7. Click NEGATIVE.

  8. Select the file and click Download.

  9. Play the file and verify it is in Spanish.

  10. Click Amazon S3.

  11. Click the link for the input bucket.

  12. Click Upload.

  13. Drag the good-tea.m4a file into the upload window.

  14. Click Upload.

  15. Navigate back to the step functions tab.

  16. Click lab-step-functions at the top.

  17. Click the new execution in process.

  18. Once all steps are green, navigate back to the S3 console tab.

  19. Click Amazon S3.

  20. Click the link for the output bucket.

  21. Click POSITIVE. If there is not a POSITIVE folder, click the refresh button.

  22. Select the file and click Download.

  23. Play the file and verify it is in Spanish.

Conclusion

Congratulations, you've completed this hands-on lab!