Hello. This is Satchie. Since it is neat, I misunderstood the day of the week to post last week. Excuse me. The day before, @ Rimo1129 (junior) wrote Make something like a job hunting portfolio on AWS ~ !!!!! As a job hunting chan, it is too good to write an Advent calendar. Right. I don't understand AWS at all, so please let me know. I don't know AWS, so I would like to play with Google Cloud Functions provided by Google.
Cloud Functions is a serverless execution environment that you can use to create and connect to cloud services. Cloud Functions allows you to create simple, single-purpose functions related to events that occur in your cloud infrastructure or services. The function is triggered when the event of interest occurs.
That's right. It's like AWS lambda. This time, by specifying HTTP as a trigger, we will deploy the API serverlessly so that it can be hit.
In Previous article, we collected information on restaurants around the company using the API of Gurunavi. This time I'm going to deploy a function that takes a keyword and a search method (and or or) as parameters and returns a list of store information that contains the keyword in the word of mouth. Since the data was small, I will prepare it in the following json without putting it in the database.
[{'id': '1046494',
'name': 'Jinya',
'longitude': '139.712244',
'latitude': '35.647473',
'holiday': '',
'opentime': 'Mon-Fri Lunch: 11:30~14:00(L.O.13:30), Dinner: 17:00~23:30(L.O.22:30)(* Takeout 11:30~22:00 (reception on the day 11:30~21:30))\n Saturdays, Sundays, and holidays 11:30~23:30(L.O.22:30)(* [Happy hour] Saturdays, Sundays, and holidays 14:00~18:00! 200 yen drinks available!\n * Take-out reception is 11:30~22:00)',
'category': 'Izakaya',
'pr': '',
'url_mobile': 'http://mobile.gnavi.co.jp/shop/1046494/?ak=m%2Bqqz7dSuc6%2FTCXqzE3tXC%2FHVysBRwNGyp5Ud0dSNe8%3D',
'image_url': '',
'review_text': 'There is a small vial on the shaved ice and it is chilled well. The one with chicken and okura. The one with chicken and yuba. This is refreshing and the richness of the chicken is beautiful. It was a hearty bowl with chicken soboro bowl with hot balls. It is a hearty exquisite set of ramen, rice and pork. It is a lunch with sweet and sour simmered sardines. It goes perfectly with the buns, so it stays hot because it's brought along with the steamed pork. It's a nice notice. It's just like roasting it and cooking it. There is a small small bottle on top of it. It's chilled well. It's got sardines and okra. It's simmered with sardines and yuba. It's refreshing and has a nice appearance. It's a hearty bowl with fried chicken and on-centric egg, and it's a hearty dish with ramen, rice, and pork. It's a lunch. It's a fluffy VANS with sweet tofu skin. It goes well with the steamed pork, so it stays hot and nice. It seems that it's just roasted and cooked. Recommended for those who like a fairly rare, soft-tasting lever.'},
{'id': '5237768',
'name': 'IL BOCCALONE',
'longitude': '139.712111',
'latitude': '35.647784',
'holiday': '',
'opentime': 'Mon-Sat 17:30~24:00(L.O.23:00)\n days 17:30~23:00(L.O.22:00)',
'category': 'Italian',
'pr': '',
'url_mobile': 'http://mobile.gnavi.co.jp/shop/5237768/?ak=m%2Bqqz7dSuc6%2FTCXqzE3tXC%2FHVysBRwNGyp5Ud0dSNe8%3D',
'image_url': '',
'review_text': 'The fitcine was entwined with the rich sauce and it was delicious. Even though it is a black cabbage, the classic Parmesan cheese risotto is not only the power of the whole cheese but also the strong taste is really addictive Recommended ☆ Outside The crispy and tender meat is the most delicious. The umami of the shrimp is on the whole surface and you will want to go again. The fitcine is entwined with the rich sauce. The black cabbage is a classic parmesan cheese that is heavier than you think. The risotto is not only the power of the whole cheese, but also the strong taste is addictive. The deliciousness of the cheese is really melted. The outside is crispy and the soft meat is the best. The taste of shrimp is on the whole surface and it is delicious to go again.'}]···Continue
This time we will create a function on the GCP console. Of course, you can also deploy locally with gcloud commands. We will create a function. Specify HTTP for the trigger here. When exposing authentication as an API, allow unauthenticated calls.
Next, set the runtime to Python, write the required packages in requirements.txt, and change the entry point to the name of the function you want to execute. Also, when using Cloud Function for the first time, it is necessary to enable Cloud Build from the point of "Enable API". After that, write a function and add any necessary files. (This time shop_data.json is added)
A green checkmark will appear when the deployment is complete.
Hit
curl "https://asia-northeast1-<Project name>.cloudfunctionsnet/ebimog-api?keywords=Horse,Italian&retrieval_type=or"
{
"results": [
{
"id": "5351809",
"name": "Uncle Tom",
"longitude": "139.711817",
"latitude": "35.647634",
"holiday": "",
"opentime": "",
"category": "pasta",
"pr": "",
"url_mobile": "http://mobile.gnavi.co.jp/shop/5351809/?ak=m%2Bqqz7dSuc6%2FTCXqzE3tXC%2FHVysBRwNGyp5Ud0dSNe8%3D",
"image_url": ""
},
{
"id": "5497878",
"name": "AFURI",
"longitude": "139.710687",
"latitude": "35.648240",
"holiday": "Nothing",
"opentime": "Mon-Sun Lunch / Supper: 11:00-5 the next day:00",
"category": "ramen",
"pr": "The motto is "nostalgic taste" ramen that you will want to eat again.",
"url_mobile": "http://mobile.gnavi.co.jp/shop/5497878/?ak=m%2Bqqz7dSuc6%2FTCXqzE3tXC%2FHVysBRwNGyp5Ud0dSNe8%3D",
"image_url": ""
},
{
"id": "6145400",
"name": "Meat sushi Ebisu Yokocho store",
"longitude": "139.710681",
"latitude": "35.648097",
"holiday": "Open all year round\n * We will be closed during the year-end and New Year holidays.",
"opentime": "Mon-Sat, the day before public holidays 15:00-5 the next day:00\n days / holidays 15:00~23:00",
"category": "Meat sushi",
"pr": "Nigiri sushi specializing in meat, mainly beef and horse meat. That is meat sushi.!!!\n\n Open until 5 am!\n There is no choice but to eat the famous Sashitoro!",
"url_mobile": "http://mobile.gnavi.co.jp/shop/6145400/?ak=m%2Bqqz7dSuc6%2FTCXqzE3tXC%2FHVysBRwNGyp5Ud0dSNe8%3D",
"image_url": ""
},・ ・ ・ The following is omitted
It's back!
In this way, the API was easily created just by registering the function from the console. There are various triggers other than HTTP, so it seems fun to master the GCP service.
-I tried using Python with Google Cloud Functions (using Beta)
Recommended Posts