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>
--Official tutorial https://aws.amazon.com/jp/getting-started/hands-on/build-web-app-s3-lambda-api-gateway-dynamodb/module-three/
Recommended Posts