The amplify docks here says that we can configure a lambda function as a dynamodb trigger by running **amplify add function**
and selecting the "Lambda Trigger" option, but when I run the "amplify add api"
(selected Python as runtime language) I am not getting the lambda trigger option, I'm only getting the "Serverless function" and "lambda layer" options.
Please help me to resolve this issue to access the feature.
docs snapshot - showing 4 options
my CLI snapshot - showing only 2 options
I know it works for nodejs runtime lambda, but I want this option for Python Lambda as well.
Just followed these steps with amplify CLI version 4.50.2
.
To create a lambda function that is triggered by changes to a DynamoDB table, you can use the following command line actions, which are walked-through inside of the CLI after entering the below command:
amplify add function
Select which capability you want to add:
Provide an AWS Lambda function name:
Choose the runtime that you want to use:
Choose the function template you want to use
What event source do you want to associate with the lambda trigger
Choose a DynamoDB event source option
Choose the graphql @model(s)
Do you want to trigger advanced settings
api
resource that contains the graphql schema that defines the table that drives the eventDo you want to access other resources in this project from your Lambda function?
After this, the other options (layer, call scheduling) are up to you.
After creating the function via the above CLI options, you can change the "Runtime"
field inside the -cloudformation-template.json file inside function directory, eg if you want a python lambda function change the runtime to "python3.8". You will also need to create a file called index.py
inside your function's directory which has a handler(event, context)
function. See example below:
import json
def handler(event, context):
print("Triggered via DynamoDB")
print(event)
return json.dumps({'status_code': 200, "message": "Received from DynamoDB"})
After making these edits, you can run amplify push
and, if you open your fxn in the management console online, it should show an attached dynamoDB stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With