How did I created EC2 by Voice?
Tags: serverless, aws, eventdriven
Published: 2022-06-08 01:55:08

AWS is amazing, the services and the interconnection parts makes it fun and really enjoyable to work with, even for fun projects like this.
Do you want to try it? [Click here](https://github.com/imohd23/voice-to-infra)

So, I was bored and decided: I want to launch EC2 with voice! Pretty simple. The diagram will show you how:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0077zugbj3rm9o3aq39.png)

The diagram shows the whole story, but let's describe it a bit.

**1- The record:**

The first step is to create a unified statement that you want your transcription job to turn into text, which will be processed by the function.
For this example, I used a website to record my voice and to download it as mp3.

**2- Upload the file:**

Once I got the record, I uploaded it into S3 and let it work. I configured my bucket to send S3 payload into Lambda that I created to deal with what gets passed from this bucket action.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwgu2mhkknb3mdj53bin.png)

Then, Lambda and Transcribe time come.

**3- Lambda time:**

Once the payload triggers the function, I get what I need from the payload to pass it into Transcribe. These are straight forward steps.

I let it to identify the language because I didn't know the recorded voice will be with which accent. If I recorded it with my accent, I believe it will get a hard time understanding the Arabic accent of my English.

```
transcribeJob = transcribe.start_transcription_job(
                TranscriptionJobName=transcribeJobName,
                Media={
                     'MediaFileUri': 's3://'+bucketName+'/'+fileName
                       },
                IdentifyLanguage= True
)
```

Then, waiting for Transcribe to finish its job.

**4- Transcribe:**

Transcribe is a fast service, despite that my record is short, the response you get is relatively fast.
So, I get the job status and look for `TranscriptionJobStatus`. Once I get `Completed`, I get the link that holds the text for my job.

This is an example from the console:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u28jsaix44bhy7zq4w1n.png)

I do some basic verification over the words as I set the function to get some keywords like Create and Option to identify the action I want to do.

The next step is to check the resource that I want to make. I hardcoded it as I did the minimal for this example. But, as always, the sky is the limit.

**5- Creation time:**

Once all the previous steps are done, I loop over the pre-config list that I made and get the parameters to pass it into the command. In my case here is creating an EC2 instance.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/or70ss5g3xrw95xk7mgo.png)

And here you go, an instance got created because of a voice record.

**To conclude:**

There are many things you can do with event-driven architecture. This is a small, fun, waste of time for some, but great evidence that this kind of architecture is powerful. I did lambda execution via SMS before and it was fun. Check it out if you're interested in this kind of unusual actions with AWS Lambda.