A memo when creating an environment that can be debugged with Lambda @ Edge for the time being

Thing you want to do

Make something that works with the minimum configuration when developing with Lambda @ Edge I want to develop while debugging using it Language is Python 3.7 (3.8 is not currently supported)

Constitution

Request → CloudFront → S3 Insert Lamda @ Edge that outputs logs to CloudWatch Logs and does nothing else

Preparation of S3

Make a suitable bucket with S3 Put an appropriate index.html (this time it looks like this)

index.html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="ja">
<head>
<title>Test homepage</title>
</head>
<body>
<h1>Test homepage</h1>
<p>It is under construction now.
</body>
</html>

Give your bucket public access スクリーンショット 2020-01-07 12.48.49.png

Check if index.html can be displayed in the browser from the "object URL" of the bucket

If you can display it, S3 setting is completed Turn on S3 static hosting settings and specify index.html

CloudFront and S3 integration

The more you look up, the more materials you will find, so I will omit it. Check if you can access S3 via CloudFront domain and display it in the browser Complete when displayed

Now you have Request → CloudFront → S3 This is the preparation Lambda @ Edge is sandwiched here

Lambda@Edge First make the ** region (the one next to the logged-in username) Virginia and then ** create a Lambda function

Make the contents of Lambda this

lambda_function.py


import json

def lambda_handler(event, context):

    print('# lambda@edge start')
    print(event)

#In the case of Viewer Response Origin Response, uncomment this
#    cfResponse = event['Records'][0]['cf']['response']
#    return cfResponse

#Uncomment this for Viewer Request Origin Request
#    cfRequest = event['Records'][0]['cf']['request']
#    return cfRequest

・ Lambda @ Edge has required parameters for request and response, otherwise an error will occur.

After confirming that the version is LATEST, select Action → Deploy to Lambda @ Edge Set the ID of CloudFront created in the distribution You can deploy by setting the Lambda @ Edge event you want to set in the CloudFront event and clicking Deploy

Since it is a CDN, there are areas where content distribution has not been completed for a while even after deploying Delivery is complete if the status changes from in Progress to deployed on the CloudFront console It seems that the completion itself was delivered in a few minutes to enough, or in 1 to 3 minutes to Japan.

Now if you look at the Lambda execution log of CloudWatch Logs, you should see the log written in the code All you have to do is debug what you want to do with Lambda @ Edge and implement it on Lambda.

About Lambda @ Edge logs (important)

Please note that Lambda @ Edge's CloudWatch Logs are written to different groups according to the following classification (I was most addicted to it) ** Log of tests run from the console ** Region: Virginia Output target: For each function ** Lambda log running on Lambda @ Edge ** Region; Region accessed (almost Tokyo in Japan) Output target: For each function ** Lambda @ Edge log running on Lambda @ Edge ** Region; Region accessed (almost Tokyo in Japan) Output target: For each output target associated with Lambda @ Edge

I hope this memo helps someone, including myself

Recommended Posts

A memo when creating an environment that can be debugged with Lambda @ Edge for the time being
A memo when creating a python environment with miniconda
Understand the probabilities and statistics that can be used for progress management with a python program
About the matter that torch summary can be really used when building a model with Pytorch
Note when creating an environment with python
[Python] Code that can be written with brain death at the beginning when scraping as a beginner
A class for PYTHON that can be operated without being aware of LDAP
Make a histogram for the time being (matplotlib)
Use logger with Python for the time being
Creating an environment for OSS-DB Silver # 1_Create a Linux environment (CentOS7 virtual environment) with VirtualBox/Vagrant
I played with Floydhub for the time being
Commands for creating a python3 environment with virtualenv
A memo for creating a python environment by a beginner
[Windows] The problem that an error occurs when opening a file other than CP932 (Shift-JIS) encoded in Python has been solved for the time being.
Libraries that should be included when creating APIs in the Django Rest Frakework environment, vscode extensions, etc. (for beginners)
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]
I will try to summarize the links that seem to be useful for the time being
Until you can install blender and run it with python for the time being
A memo that I touched the Datastore with python
Creating a list when the nomenclature is a fixed time
The shortest memo for building a python environment that takes less than 5 minutes to work.
About the contents of wscript when building a D language environment like that with Waf
Creating an environment that automatically builds with Github Actions (Android)
Precautions that must be understood when building a PYTHON environment
I investigated the pretreatment that can be done with PyCaret
Let's make a diagram that can be clicked with IPython
I want to create a Dockerfile for the time being.
I made a function to check if the webhook is received in Lambda for the time being
[Python] A program that finds the maximum number of toys that can be purchased with your money
[Python] Make a graph that can be moved around with Plotly
Precautions when creating a two-dimensional array with all the same values
Make a Spinbox that can be displayed in Binary with Tkinter
Switch the package to be installed for each environment with poetry
A timer (ticker) that can be used in the field (can be used anywhere)
I made a shuffle that can be reset (reverted) with Python
When creating an environment that uses python django on Ubuntu 12.04 LTS
Make a currency chart that can be moved around with Plotly (2)
For the time being, I want to convert files with ffmpeg !!
Make a Spinbox that can be displayed in HEX with Tkinter
Make a currency chart that can be moved around with Plotly (1)
A memo for when pip3 is installed with python2.7 for some reason
It seems that some RHEL will be free with a big boo for the end of CentOS
About the matter that the re.compiled object can be used for the re.match pattern
Things to watch out for when creating a Python environment on a Mac
I created a template for a Python project that can be used universally
Challenge image classification with TensorFlow2 + Keras CNN 1 ~ Move for the time being ~
The LXC Web Panel that can operate LXC with a browser was wonderful
Create a web app that can be easily visualized with Plotly Dash
A memo that allows you to change Pineapple's Python environment with pyenv
Mathematical optimization that can be used for free work with Python + PuLP
[Python memo] Be careful when creating a two-dimensional array (list of lists)
Draw a graph that can be moved around with HoloViews and Bokeh
I made a simple timer that can be started from the terminal
Impressions and memorandums when working with VS code for the first time
A useful note when using Python for the first time in a while
Be careful of the type when making an image mask with Numpy
[Python3] Code that can be used when you want to cut out an image in a specific size
[Python] Creating a tool that can list, select, and execute python files with tkinter & about the part that got caught
The story that had nothing to do with partitions when I did disk backup with dd for the first time
Article that can be a human resource who understands and masters the mechanism of API (with Python code)
[Python3] Code that can be used when you want to change the extension of an image at once