ab61a49f84
SSIA
1.3 KiB
1.3 KiB
Hello Function - Solution
Exercise
Create a basic AWS Lambda function that when given a name, will return "Hello "
Solution
Define a function
-
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
Function's code
import json
def lambda_handler(event, context):
firstName = event['name']
return 'Hello ' + firstName
- Click on "Create Function"
Define a test
- 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"
Test the function
- 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