AWS lambda documentation change
Summary
Restructured tutorial steps, removed prerequisites section, converted CLI-based Lambda creation/testing to console-based workflow, added PowerShell examples for curl commands, and updated testing procedures
Security assessment
Changes focus on workflow modernization and multi-platform support without addressing vulnerabilities or security features. The removed CLI steps and added console instructions represent usability improvements rather than security fixes. No mention of CVEs, vulnerabilities, or new security controls.
Diff
diff --git a/lambda/latest/dg/services-apigateway-tutorial.md b/lambda/latest/dg/services-apigateway-tutorial.md index 606ff803d..fa8940beb 100644 --- a//lambda/latest/dg/services-apigateway-tutorial.md +++ b//lambda/latest/dg/services-apigateway-tutorial.md @@ -5 +5 @@ -PrerequisitesCreate a permissions policyCreate an execution roleCreate the functionInvoke the function using the AWS CLICreate a REST API using API GatewayCreate a resource on your REST APICreate an HTTP POST methodCreate a DynamoDB tableTest the integration of API Gateway, Lambda, and DynamoDBDeploy the APIUse curl to invoke your function using HTTP requestsClean up your resources (optional) +Create a permissions policyCreate an execution roleCreate the Lambda functionTest the functionCreate a REST API using API GatewayCreate a resource on your REST APICreate an HTTP POST methodCreate a DynamoDB tableTest the integration of API Gateway, Lambda, and DynamoDBDeploy the APIUse curl to invoke your function using HTTP requestsClean up your resources (optional) @@ -34,41 +33,0 @@ By completing these stages, you will learn how to use API Gateway to create an H -###### Sections - - * Prerequisites - - * Create a permissions policy - - * Create an execution role - - * Create the function - - * Invoke the function using the AWS CLI - - * Create a REST API using API Gateway - - * Create a resource on your REST API - - * Create an HTTP POST method - - * Create a DynamoDB table - - * Test the integration of API Gateway, Lambda, and DynamoDB - - * Deploy the API - - * Use curl to invoke your function using HTTP requests - - * Clean up your resources (optional) - - - - -## Prerequisites - -If you have not yet installed the AWS Command Line Interface, follow the steps at [Installing or updating the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) to install it. - -The tutorial requires a command line terminal or shell to run commands. In Linux and macOS, use your preferred shell and package manager. - -###### Note - -In Windows, some Bash CLI commands that you commonly use with Lambda (such as `zip`) are not supported by the operating system's built-in terminals. To get a Windows-integrated version of Ubuntu and Bash, [install the Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10). - @@ -77,2 +35,0 @@ In Windows, some Bash CLI commands that you commonly use with Lambda (such as `z - - @@ -131,2 +87,0 @@ Before you can create an [execution role](./lambda-intro-execution-role.html) fo - - @@ -154 +109 @@ An [execution role](./lambda-intro-execution-role.html) is an AWS Identity and A -Later in the tutorial, you need the Amazon Resource Name (ARN) of the role you just created. On the **Roles** page of the IAM console, choose the name of your role (`lambda-apigateway-role`) and copy the **Role ARN** displayed on the **Summary** page. +## Create the Lambda function @@ -156 +111 @@ Later in the tutorial, you need the Amazon Resource Name (ARN) of the role you j -## Create the function + 1. Open the [Functions page](https://console.aws.amazon.com/lambda/home#/functions) of the Lambda console and choose **Create Function**. @@ -158 +113 @@ Later in the tutorial, you need the Amazon Resource Name (ARN) of the role you j - + 2. Choose **Author from scratch**. @@ -160 +115 @@ Later in the tutorial, you need the Amazon Resource Name (ARN) of the role you j -The following code example receives an event input from API Gateway specifying an operation to perform on the DynamoDB table you will create and some payload data. If the parameters the function receives are valid, it performs the requested operation on the table. + 3. For **Function name** , enter `LambdaFunctionOverHttps`. @@ -162 +117 @@ The following code example receives an event input from API Gateway specifying a -Node.js + 4. For **Runtime** , choose the latest Node.js or Python runtime. @@ -163,0 +119 @@ Node.js + 5. Under **Permissions** , expand **Change default execution role**. @@ -165 +121,7 @@ Node.js -###### Example index.mjs + 6. Choose **Use an existing role** , and then select the `lambda-apigateway-role` role that you created earlier. + + 7. Choose **Create function**. + + 8. In the **Code source** pane, replace the default code with the following Node.js or Python code. + +Node.js @@ -167 +128,0 @@ Node.js -Note the `region` setting. This must match the AWS Region where you deploy the function and create the DynamoDB table. @@ -168,0 +130,3 @@ Note the `region` setting. This must match the AWS Region where you deploy the f +The `region` setting must match the AWS Region where you deploy the function and create the DynamoDB table. + +###### Example index.mjs @@ -220,26 +184 @@ Note the `region` setting. This must match the AWS Region where you deploy the f -###### Note - -In this example, the name of the DynamoDB table is defined as a variable in your function code. In a real application, best practice is to pass this parameter as an environment variable and to avoid hardcoding the table name. For more information see [Using AWS Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html). - -###### To create the function - - 1. Save the code example as a file named `index.mjs` and, if necessary, edit the AWS region specified in the code. The region specified in the code must be the same as the region in which you create your DynamoDB table later in the tutorial. - - 2. Create a deployment package using the following `zip` command. - - zip function.zip index.mjs - - 3. Create a Lambda function using the `create-function` AWS CLI command. For the `role` parameter, enter the execution role's Amazon Resource Name (ARN) that you copied earlier. - - aws lambda create-function \ - --function-name LambdaFunctionOverHttps \ - --zip-file fileb://function.zip \ - --handler index.handler \ - --runtime nodejs22.x \ - --role arn:aws:iam::123456789012:role/service-role/lambda-apigateway-role - - - - -Python 3 - +Python @@ -247 +185,0 @@ Python 3 -###### Example LambdaFunctionOverHttps.py @@ -248,0 +187 @@ Python 3 +###### Example lambda_function.py @@ -303,3 +242 @@ In this example, the name of the DynamoDB table is defined as a variable in your -###### To create the function - - 1. Save the code example as a file named `LambdaFunctionOverHttps.py`. + 9. In the **DEPLOY** section, choose **Deploy** to update your function's code: @@ -307 +244 @@ In this example, the name of the DynamoDB table is defined as a variable in your - 2. Create a deployment package using the following `zip` command. + @@ -309 +245,0 @@ In this example, the name of the DynamoDB table is defined as a variable in your - zip function.zip LambdaFunctionOverHttps.py @@ -311 +246,0 @@ In this example, the name of the DynamoDB table is defined as a variable in your - 3. Create a Lambda function using the `create-function` AWS CLI command. For the `role` parameter, enter the execution role's Amazon Resource Name (ARN) that you copied earlier. @@ -313,6 +247,0 @@ In this example, the name of the DynamoDB table is defined as a variable in your - aws lambda create-function \ - --function-name LambdaFunctionOverHttps \ - --zip-file fileb://function.zip \ - --handler LambdaFunctionOverHttps.lambda_handler \ - --runtime python3.12 \ - --role arn:aws:iam::123456789012:role/service-role/lambda-apigateway-role @@ -319,0 +249 @@ In this example, the name of the DynamoDB table is defined as a variable in your +## Test the function @@ -320,0 +251 @@ In this example, the name of the DynamoDB table is defined as a variable in your +Before integrating your function with API Gateway, confirm that you have deployed the function successfully. Use the Lambda console to send a test event to your function. @@ -321,0 +253 @@ In this example, the name of the DynamoDB table is defined as a variable in your + 1. On the Lambda console page for your function, choose the **Test** tab. @@ -323 +255 @@ In this example, the name of the DynamoDB table is defined as a variable in your -## Invoke the function using the AWS CLI + @@ -325,7 +257 @@ In this example, the name of the DynamoDB table is defined as a variable in your - - -Before integrating your function with API Gateway, confirm that you have deployed the function successfully. Create a test event containing the parameters your API Gateway API will send to Lambda and use the AWS CLI `invoke` command to run your function. - -###### To invoke the Lambda function with the AWS CLI - - 1. Save the following JSON as a file named `input.txt`. + 2. Scroll down to the **Event JSON** section and replace the default event with the following. This event matches the structure expected by the Lambda function. @@ -341,8 +267 @@ Before integrating your function with API Gateway, confirm that you have deploye - 2. Run the following `invoke` AWS CLI command. - - aws lambda invoke \ - --function-name LambdaFunctionOverHttps \ - --payload file://input.txt outputfile.txt \ - --cli-binary-format raw-in-base64-out - -The **cli-binary-format** option is required if you're using AWS CLI version 2. To make this the default setting, run `aws configure set cli-binary-format raw-in-base64-out`. For more information, see [AWS CLI supported global command line options](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-options.html#cli-configure-options-list) in the _AWS Command Line Interface User Guide for Version 2_. + 3. Choose **Test**. @@ -350 +269 @@ The **cli-binary-format** option is required if you're using AWS CLI version 2. -You should see the following response: + 4. Under **Executing function: succeeded** , expand **Details**. You should see the following response: @@ -353,2 +272,2 @@ You should see the following response: - "StatusCode": 200, - "ExecutedVersion": "LATEST" + "somekey1": "somevalue1", + "somekey2": "somevalue2" @@ -357,4 +275,0 @@ You should see the following response: - 3. Confirm that your function performed the `echo` operation you specified in the JSON test event. Inspect the `outputfile.txt` file and verify it contains the following: - - {"somekey1": "somevalue1", "somekey2": "somevalue2"} - @@ -366,2 +280,0 @@ You should see the following response: - - @@ -387,2 +299,0 @@ In this step, you create the API Gateway REST API you will use to invoke your La - - @@ -393 +304 @@ To add an HTTP method to your API, you first need to create a resource for that - 1. In the [API Gateway console](https://console.aws.amazon.com/apigateway), on the **Resources** page for your API, choose **Create Resource**. + 1. In the [API Gateway console](https://console.aws.amazon.com/apigateway), on the **Resources** page for your API, choose **Create resource**. @@ -404,2 +314,0 @@ To add an HTTP method to your API, you first need to create a resource for that - - @@ -429,2 +337,0 @@ For the purpose of this tutorial, one HTTP method (`POST`) is used to invoke a s - - @@ -454,2 +360,0 @@ Create an empty DynamoDB table that your Lambda function will perform CRUD opera - - @@ -464,2 +368,0 @@ You're now ready to test the integration of your API Gateway API method with you - -