pythonでS3にアップロードします
L S3 full accessのcredentialは別ファイルからimportにします。
import boto3
import json
import credentials
str = {
"speech":"最高"
}
with open("sample.json", "w") as f:
json.dump(str, f, ensure_ascii=False)
s3 = boto3.client('s3', aws_access_key_id=credentials.Accesskey, aws_secret_access_key= credentials.Secretkey, region_name=credentials.Region)
filename = "sample.json"
bucket_name = "hogehoge"
s3.upload_file(filename,bucket_name,filename, ExtraArgs={'ContentType': "application/json",'ACL':'public-read'})
print("upload {0}".format(filename))
React.jsでJsonをsetIntervalで読み込みます
function App(){
const [data, setData] = React.useState([]);
React.useEffect(() => {
const fetchData = async() => {
fetch("https://hoge.s3.ap-northeast-1.amazonaws.com/sample.json")
.then((res) => res.json())
.then((data) =>{
setData(data);
});
}
const id = setInterval(() => {
fetchData();
}, 2000);
}, []);
console.log(data);
return(
<h1>コメント:{data.speech}</h1>
);
}
const target = document.getElementById('app');
ReactDOM.render(<App />, target);

pythonでuploadしたワードがブラウザの更新なくHTML側に表示されます。
OK、後はUIを作っていく