AWS Lambda의 Schedule Event를 사용하여 SORACOM Air의 상태를 제어해 봅니다.
그 중에서도 Python2.7 대응이나 Schedule Event는 여러분에게 영향이 있었던 것이 아닐까요.
Schedule Event는 최소 5분부터 설정하여 시간 이벤트로 Lambda Function을 실행할 수 있습니다.
시간 지정 방법은 CRON 표현으로 설정할 수 있습니다.
cron(Minutes Hours Day-of-month Month Day-of-week Year)
예를 들어,
매일 10:00am에 실행하고 싶다면
cron(0 10 * * ? *)
월요일부터 금요일 오후 6시까지 실행하고 싶다면
cron(0 18 ? * MON-FRI *)
덧붙여서, 시간은 모두 UTC에서의 지정이 됩니다.
이 기능은 CRON에서 실행하는 "자주있는"배치 시스템에서 활용할 수있는 획기적인 기능이라고 생각합니다.
물론 IoT 세계에서도 이 기능을 사용할 수 있습니다.
예를 들어 에너지 시스템으로 일출부터 일몰까지 데이터를 클라우드에 올려 밤에는 쓸데없는 통신을 억제할 수 있습니다. 이것을 API로 실행할 수 있는 것이 Soracom의 파워라고 생각합니다.
그래서 Lambda의 새로운 기능 (Python2.7과 Schedule Event)과 Soracom API를 사용해 보겠습니다.
AWS Lambda
파이썬 코드는 다음과 같습니다.
import requests
import json
def handler(event, context):
data = {}
headers = {'Content-Type': 'application/json'}
payload = {'email': 'YOUR MAIL ADDRESS', 'password': 'YOUR PASSWORD'}
res = requests.post("https://api.soracom.io/v1/auth", headers=headers,data=json.dumps(payload)).text
data = json.loads(res)
apiKey = data['apiKey']
token = data['token']
print('apiKey: ' + apiKey +'/' + 'Token: ' + token)
headers = {
'Accept': 'application/json',
'X-Soracom-Api-Key': apiKey,
'X-Soracom-Token': token
}
res = requests.get("https://api.soracom.io/v1/subscribers?tag_value_match_mode=exact",headers=headers,data=json.dumps(payload)).text
data = json.loads(res)
imsi = data[0]['imsi']
status = data[0]['status']
url = 'https://api.soracom.io/v1/subscribers/' + imsi + '/'
if status == 'inactive':
url = url + 'activate'
print 'URL: ' + url
res = requests.post(url,headers=headers).text
else:
url = url + 'deactivate'
print 'URL: ' + url
res = requests.post(url,headers=headers).text
data = json.loads(res)
return data['status']
현재 상태에 따라 Activate와 Inactivate로 매우 간단합니다.
관리 콘솔에서 Python2.7을 선택하여 zip 파일을 업로드합니다.

이벤트 소스 탭을 선택합니다.

Add event source를 클릭하고 Event source type에서 Scheduled Event를 선택합니다.
필요한 정보를 입력합니다. 이번에는 테스트로 5분 단위로 실행하도록 하겠습니다.

이것으로 설정이 끝납니다.
실행 중인지 Soracom 콘솔에서 확인해 봅시다.
처음에는 Inactive 이었지만 5 분 후에는 Active로 바뀝니다.


마지막으로
API로 제어할 수 있는 캐리어, 매우 파워풀한 것을 실감할 수 있습니다.
또한 AWS Lambda에 Schedule Event는 매우 영향력이 있다고 생각합니다.
면책
이쪽은 개인의 의견으로, 소속하는 기업이나 단체는 관계 없습니다.
Reference
이 문제에 관하여(AWS Lambda의 Schedule Event를 사용하여 SORACOM Air의 상태를 제어해 봅니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ToshiakiEnami/items/8e0a6853d6017ac693ce
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(AWS Lambda의 Schedule Event를 사용하여 SORACOM Air의 상태를 제어해 봅니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ToshiakiEnami/items/8e0a6853d6017ac693ce텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)