Create a basic AWS Lambda function that when given a name, will return "Hello "
-
Go to Lambda console panel and click on
Create function
-
Give the function a name like
BasicFunction
-
Select
Python3
runtime -
Now to handle function's permissions, we can attach IAM role to our function either by setting a role or creating a new role. I selected "Create a new role from AWS policy templates"
-
In "Policy Templates" select "Simple Microservice Permissions"
-
Next, you should see a text editor where you will insert a code similar to the following
import json
def lambda_handler(event, context):
firstName = event['name']
return 'Hello ' + firstName
- Click on "Create Function"
- Now let's test the function. Click on "Test".
- Select "Create new test event"
- Set the "Event name" to whatever you'd like. For example "TestEvent"
- Provide keys to test
{
"name": 'Spyro'
}
- Click on "Create"
- Choose the test event you've create (
TestEvent
) - Click on the
Test
button - You should see something similar to
Execution result: succeeded
- If you'll go to AWS CloudWatch, you should see a related log stream