[PYTHON] Dynamically move Amplify with Lambda

I thought Amplify could move dynamically

In Amplify, I couldn't call it even if I specified the python file as follows.


    <script>
        var callAPI = (input)=>{
            var myHeaders = new Headers();
            console.log(input)
            myHeaders.append("Content-Type", "text/html");
            var requestOptions = {
                method: 'POST',
                headers: myHeaders,
                body: input,
                redirect: 'follow'
            };
            fetch("test.py", requestOptions)
            .then(response => response.text())
            .then(result => console.log('success', result))
            .catch(error => console.log('error', error));
        }
    </script>
</head>
<body>
    <form>
        <label>Please enter the characters</label>
        <input type="text" id="input">
        <button type="button" onclick="callAPI(document.getElementById('input').value)">input</button>
    </form>
</body>

I almost copied and pasted the python file I wanted to call from html to Lambda, and I was able to execute the python program I wanted to run. It seems that just deploying is not enough to make it dynamic.

<body>
    <form>
        <label for="inhput" class="cl1">Please enter the characters</label>
        <input type="text" id="input">
        <button type="button" onclick="callAPI(document.getElementById('input').value)">input</button>
    </form>
    <script>
        var callAPI = (input)=>{
            var myHeaders = new Headers();
            myHeaders.append("Content-Type", "application/json");
            var raw = JSON.stringify({"input":input});
            var requestOptions = {
                method: 'POST',
                headers: myHeaders,
                body: raw,
                redirect: 'follow'
            };
            fetch("Write the URL of API Gateway here", requestOptions)
            .then(response => response.text())
            .then(result => alert(JSON.parse(result).body))
            .catch(error => console.log('error', error));
        }
    </script>
</body>

Reference article

--Official tutorial https://aws.amazon.com/jp/getting-started/hands-on/build-web-app-s3-lambda-api-gateway-dynamodb/module-three/

Recommended Posts

Dynamically move Amplify with Lambda
Using Lambda with AWS Amplify with Go
Make Lambda Layers with Lambda
Operate TwitterBot with Lambda, Python
Deploy Django serverless with Lambda
Easily write if-elif with lambda
Move CloudWatch logs to S3 on a regular basis with Lambda
[AWS] Create API with API Gateway + Lambda
Face detection with Lambda (Python) + Rekognition
Upload & move GCS files with Go
Dynamically create new dataframes with pandas
Notify HipChat with AWS Lambda (Python)
Use PostgreSQL with Lambda (Python + psycopg2)