Home > front end >  Run aws cli from EC2 python script with variables
Run aws cli from EC2 python script with variables

Time:11-21

I need to run AWS CLI Polly service from AWS EC2 using python, with additional variables. The problem is with the including variable in the cmd string

import subprocess
row1 = 'My husband and I have done around 100 rooms and came to Barcelona as it has a reputation for top class rooms. We did Bajo Zero based on a recommendation from an escape room enthusiast in the UK and werent disappointed. It was a very well made immersive room with some clever puzzles. We chose hard mode and it was quite challenging as a pair but we did make it out in time. ,Escapem Elements Aire Escape Room'
cmd = 'aws polly synthesize-speech --output-format mp3 --engine neural --voice-id Kevin --text'  row1  'speech1.mp3'

subprocess.call(cmd, shell=True)

This script command is executed from withing EC2 NOT local

CodePudding user response:

Rather than calling the aws program from Python, you can use the boto3 library to directly call AWS. In fact, the AWS CLI is written in Python and uses this library too!

You can then use boto3 to call Polly.

For example:

import boto3

client = boto3.client('polly')

response = client.synthesize_speech(
    Engine='neural',
    LanguageCode='en-US',
    OutputFormat='mp3',
    Text='My husband and I have done around 100 rooms',
    VoiceId='Kevin'
)
  • Related