[Free] Hit the Clash Royale API from lambda and send it to LINE

Previously, I wrote an article Put the Clash Royale API from lambda and send it to LINE.

The system itself is completed here, but there was a problem that it cost a lot of money.

The cause of this problem was that the Clash Royale API (Clash Royale API) restricted the accessible IPs. This time, by using the public proxy provided by Royale API, I was able to ** hit the Clash Royale API from lambda and send it to LINE ** for free, so I will write it as an article.

Overview

Completed

Exactly the same as the previous article, the player name and the period of neglect will arrive on LINE

Constitution

aws-and-cr-using-proxy.png

Clash Royale API needs to specify the IP address, but by using Proxy of Royale API, it is no longer necessary to fix the IP address on the AWS side.

Royale API Proxy

About Royale API

In a nutshell, it's the ** informal being closest to the official ** If you are a Clarova user, you may have heard about it, such as promptly communicating update information and collecting and publishing play data statistics.

Also, although it is currently stopped, it provided an unofficial API even before the official API of Clash Royale was provided.

How to use

As written in Document

  1. Allow the address 128.128.128.128 when creating the Clash Royale API Key
  2. Rewrite api.clashroyale.com in the URL to send the request to proxy.royaleapi.dev

Security

There are many opinions that "public proxy is dangerous"

-[Personal information extraction case] Never use a public proxy server -Beware of malicious "public proxies", passwords may be stolen

The dangers mentioned here are as you say and should be kept in mind.

The information via the Royale API Proxy will be the official Clash Royale API key in the header and the data obtained from the API. The API key is free and there are no restrictions, and I don't want to keep the data I get secret, so I think that's okay (in my opinion).

It's up to you to decide whether to take convenience or security.

Creating a Clash Royale API Key

Select My Account from the name in the upper right corner of developer.clashroyale.com and create a new key from Create New Key

Specify 128.128.128.128 for ALLOWED IP ADDRESS

スクリーンショット 2021-01-03 15.33.30.png

Generate a key with Create Key and save the created token

スクリーンショット 2021-01-03 15.43.00.png

Implementation (change from before)

Describes the changes in Old Code and Modified Code.

Please refer to Previous article for explanations other than the changes.

Change API BASE_URL

#Change before
CR_BASE_URL = 'https://api.clashroyale.com/v1'
#After change
CR_BASE_URL = 'https://proxy.royaleapi.dev/v1'

Remove unnecessary parts of serverless.yml

  #Removed description of VPC roles
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "ec2:CreateNetworkInterface"
        - "ec2:DescribeNetworkInterfaces"
        - "ec2:DeleteNetworkInterface"
      Resource:
        - "*"

  #Removed description about VPC security group
  vpc:
    securityGroupIds:
      ${env:VPC_SECURITY_GROUP_IDS}
    subnetIds:
      ${env:VPC_SUBNET_IDS}

Change API key

Add API key to .env file

CR_ACCESS_KEY_EIP=[Old API key]
CR_ACCESS_KEY_PROXY=[API key created this time]

Change the environment variable of API key set in serverless.yml

# you can define service wide environment variables here
  environment:
    #Change before
    CR_ACCESS_KEY: ${env:CR_ACCESS_KEY_EIP}
    #After change
    CR_ACCESS_KEY: ${env:CR_ACCESS_KEY_PROXY}

Finally, run serverless deploy and you're done

At the end

Thanks to RoyaleAPI, he returned to Lambda, who can do anything easily.

Royale API is a site operated by volunteers. You can help from the Donate Page You can also help with the creator code Royale API.

This configuration is free thanks to the Royale API. Let's support with the creator code etc.!

Recommended Posts

[Free] Hit the Clash Royale API from lambda and send it to LINE
[python] Send the image captured from the webcam to the server and save it
How to get followers and followers from python using the Mastodon API
[EC2] How to install and download chromedriver from the command line
From the introduction of GoogleCloudPlatform Natural Language API to how to use it
Output the report as PDF from DB with Python and automatically attach it to an email and send it
Get the latest schedule from Google Calendar and notify it on LINE every morning
How to create an article from the command line
Clear the cron.log regularly to prevent it from growing.
Send log data from the server to Splunk Cloud
Send and receive Gmail via the Gmail API using Python
PHP and Python samples that hit the ChatWork API
How to hit the document of Magic Function (Line Magic)
How to post a ticket from the Shogun API
Let's add it to the environment variable from the command ~
A script that makes it easy to create rich menus with the LINE Messaging API
Read the function name from the DB and execute it dynamically
[LINE Notify API, AWS] Regularly send buzzing tweets to group LINE
Throw appointments to others with the LINE WORKS calendar API
[Python] I installed the game from pip and played it
How to hit NAPALM from the Web (NetDevOpsSec reality solution)
I want to send a message from Python to LINE Bot
Send a request from AWS Lambda to Amazon Elasticsearch Service
I tried to get various information from the codeforces API
The Like (LGTM) order has disappeared from My Page, so use the Qiita API to get it.
Create a model to store information from the Google Books API for intuitive handling and testing
Process the gzip file UNLOADed with Redshift with Python of Lambda, gzip it again and upload it to S3
Send the temperature, humidity, etc. measured by SensorTag to Ambient via Raspberry Pi 3 and graph it.
Read the old Gakushin DC application Word file (.doc) from Python and try to operate it.