How to trigger an AWS Lambda function that takes input from a Flutter form when a submit button is pressed

Viewed 237

I have a Lambda function, which currently works. It takes three strings as input and makes an entry in DynamoDB.

I have a Flutter app (which is additionally an AWS Amplify project.)

The code for the Lambda function is as follows:

import json
import logging
import os
import time
import uuid

import boto3

dynamodb = boto3.resource('dynamodb')

def create(event, context):
   
    timestamp = str(time.time())

    table = dynamodb.Table(os.environ['DYNAMODB_TABLE'])

    item = {
        'id': str(uuid.uuid1()),
        'name': event['name'],
        'description': event['description'],
        'price': event['price'],        
        'createdAt': timestamp,
        'updatedAt': timestamp,
    }

    # write the todo to the database
    table.put_item(Item=item)

    # create a response
    response = {
        "statusCode": 200,
        "body": json.dumps(item)
    }

    return response

The form in my Flutter application consists of three text fields and a submit button. I want the three fields to take the item's name, description and price, and trigger the AWS Lambda function to create an entry for the DynamoDB table when he button is pressed.

However, I cannot find any documentation on guide as to how I can use Dart's onpressed feature to successfully trigger the function that takes these three strings as input and creates the entry.

I am open to alternate ways of achieving this if this is impossible using my current design.

0 Answers
Related