Skip to content

Instantly share code, notes, and snippets.

@shiro01
Last active May 21, 2018 07:24
Show Gist options
  • Save shiro01/488d6532e835d5736c9b10580bc6bcfe to your computer and use it in GitHub Desktop.
Save shiro01/488d6532e835d5736c9b10580bc6bcfe to your computer and use it in GitHub Desktop.
lambda test. env, url, cmd
import json
import os
import urllib.request
import subprocess
def lambda_handler(event, context):
test = test_event_param(event)
#submit_url()
#cmd_exec()
return test
# get param test
def test_event_param(event):
env_value = os.environ['foo']
print(json.dumps(event))
event_param = {env_value : event["test"]}
return event_param
# urllib test
def submit_url():
url = "http://example.com"
with urllib.request.urlopen(url) as res:
html = res.read().decode("utf-8")
print(html)
# cmd test
def cmd_exec():
word = 'hoge'
cmd = ['echo', word]
out = subprocess.run(cmd, stdout=subprocess.PIPE)
print(out.stdout.decode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment