# I built an AWS Lambda function to prepare my meals using AI

> ***This is Day#2 of the #****ServerlessChallenge* ***challenge, where I'm creating/building serverless apps using different AWS services.***

**Short description**: An API that accepts a list of food/ingredients that I have and returns meal ideas that I can prepare.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698417770181/676b71bb-1af8-49d0-aa98-0bb2006b55e7.png align="center")

### **The long/tech description**

Using Amazon Bedrock (Jurassic-2 Mid model) to generate some meal ideas and the steps for preparing it after getting the input of the available ingredients and the number of needed meals:

The prompt text is so simple but it's enough to make sure that the output will be as I want, also the max number of tokens is limited to 200 which is enough <s>Don't want to be surprised by the invoice </s> [<s>🏃</s>](https://emojipedia.org/person-running)<s>-</s>

```typescript
  const command: InvokeModelCommand = new InvokeModelCommand({
    modelId: process.env.BEDROCK_TEXT_MODEL,
    contentType: "application/json",
    accept: "*/*",
    body: JSON.stringify(
      {
        prompt: `Recommend only ${numberOfMeals} meal(s) Which i can make only by using ${ingredients.join(',')}`,
        maxTokens: 200,
        temperature: 0.7,
        topP: 1
      }
    )
  });
```

The trigger of the lambda function is the endpoint `/meals` (API Gateway) with the following event schema which has the list of the ingredients & the needed number of meals:

```typescript
default {
  type: "object",
  properties: {
    ingredients: {type: 'string'},
    count: {type: 'number'}
  },
  required: ['ingredients', 'count']
} as const;
```

```typescript
  events: [
    {
      http: {
        method: 'get',
        path: 'meals',
        request: {
          schemas: {
            'application/json': schema,
          },
        },
      },
    },
  ]
```

So, to wrap that up, simple the function is:

* Receiving a list of ingredients and the number of meals
    
* Invoking the model to get some meal ideas
    
* Responding with the ai response
    

GitHub repo: [**https://github.com/Rochdy/mealsRecommender**](https://github.com/Rochdy/mealsRecommender)

That was the app of Day#2! looking forward to posting soon about the next app
