[AWS] Create a Python Lambda environment with CodeStar and do Hello World

Introduction

Overview

Recently, we are developing using AWS CodeStar. CodeStar is roughly understood as a service that combines a CI / CD service and a dashboard. The CI / CD tool is also packaged and created, so the code you write will be reflected immediately, which is convenient when you want to give it a try. However, when I made it (I am a beginner of AWS), I often stumbled around the authority. We plan to update S3 access, Lambda VPC placement, and EC2 projects from time to time.

First, edit and push the code with a local text editor to check the changes.

Premise

--Work date: 2020/4/11 --Local environment

CodeStar project creation procedure

  1. Open the CodeStar service by searching for codestar from the AWS Management Console image.png

  2. Create a new project image.png

  3. This time select the "Python Web Service Lambda" template image.png

  4. This time, the project name is "hello-world-codestar", the project ID is "codestar-test", and the repository uses CodeCommit.

  1. Press "Create Project" with the "AWS CodeStar ~ (Omitted) ~" checkbox checked.
  1. Creating repository ... (When the repository is created, the URL of the repository created in CodeCommit will be displayed.) Select "Skip".
  1. Creating a project ... after the creation is completed image.png image.png

  2. In this state, you can check the response from Lambda of the initial template by accessing "Application Endpoint" in the dashboard. image.png

Code editing on a local PC ~ Text editor ~

  1. Select "Connect to Tool" from the dashboard screen of the created project and copy the repository URL.
  1. Clone the URL copied by the CLI of the local machine, in the case of the first clone [Git credentials](https://docs.aws.amazon.com/ja_jp/codestar/latest/userguide/getting-started.html#git- You need to enter the user name / password of credentials)

  2. The hierarchy of the cloned code is as follows, this time edit "index.py" and check that the response of Lambda changes

  1. Edit and save index.py, in the example below, "Code Star!" Is added to the output value.

index.py


import json
import datetime


def handler(event, context):
    data = {
        # 'output': 'Hello World',
        'output': 'Hello World CodeStar!',
        'timestamp': datetime.datetime.utcnow().isoformat()
    }
    return {'statusCode': 200,
            'body': json.dumps(data),
            'headers': {'Content-Type': 'application/json'}}
  1. Add → commit → push to reflect the changes in the remote repository
  1. If the push is successful, the PipeLine status will be updated on the CodeStar dashboard. image.png

  2. Confirm that Deploy is completed and the status of all phases is Green, access the endpoint of the app, and confirm that the code change is reflected. image.png

at the end

--The following describes how to create a CodeStar project and how to edit code with a text editor, but you can also edit code and push with IDE. ――Looking back, I realized that there is a surprising process just by editing and pushing locally.

(Remarks) About CodeStar project ID

Select the project at the bottom left of the dashboard image.png

When opened, you will see the project details and a list of resources created by CodeStar. As you can see, the project ID set in creation step 4 is used everywhere, which is why you need to be careful because the project ID cannot be changed as mentioned above. (If anyone knows how to change the project ID, please let me know!) image.png

Recommended Posts

[AWS] Create a Python Lambda environment with CodeStar and do Hello World
Create a Layer for AWS Lambda Python with Docker
Create a virtual environment with Python!
python / tensorflow beginners build jupyter + tensorflow environment and do Hello World
[Python] Create a virtual environment with Anaconda
Install pip in Serverless Framework and AWS Lambda with Python environment
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
Create a simple Python development environment with VS Code and Docker
I wrote a script to create a Twitter Bot development environment quickly with AWS Lambda + Python 2.7
Hello World and face detection with OpenCV 4.3 + Python
Building a python environment with virtualenv and direnv
Create a virtual environment with conda in Python
Create a python3 build environment with Sublime Text3
Create a one-file hello world application with django
Create a Python environment
First python ① Environment construction with pythonbrew & Hello World !!
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Create a "Hello World" (HTTP) server with Tornado
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
Dynamic HTML pages made with AWS Lambda and Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Create a python development environment with vagrant + ansible + fabric
Build a python virtual environment with virtualenv and virtualenvwrapper
Make ordinary tweets fleet-like with AWS Lambda and Python
Create a decent shell and python environment on Windows
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Do Django with CodeStar (Python3.8, Django2.1.15)
Create a directory with python
Python starting with Hello world!
Quickly create a Python data analysis dashboard with Streamlit and deploy it to AWS
Until you create a machine learning environment with Python on Windows 7 and run it
Let's create a PRML diagram with Python, Numpy and matplotlib.
Create a simple Python development environment with VSCode & Docker Desktop
I just built a virtual environment with AWS lambda layer
Create API with Python, lambda, API Gateway quickly using AWS SAM
Site monitoring and alert notification with AWS Lambda + Python + Slack
[AWS] Create API with API Gateway + Lambda
Create a Python environment on Mac (2017/4)
Building a virtual environment with Python 3
[Note] Hello world output with python
Create a python environment on centos
Notify HipChat with AWS Lambda (Python)
Create a Python execution environment for Windows with VScode + Remote WSL
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a Python environment on your Mac with Anaconda and PyCharm
Create a striped illusion with gamma correction for Python3 and openCV3
Try to create a python environment with Visual Studio Code & WSL
From building a Python environment for inexperienced people to Hello world
Make a scraping app with Python + Django + AWS and change jobs
Prepare an environment to use OpenCV and Pillow with AWS Lambda
[Python] I wrote a REST API using AWS API Gateway and Lambda.
Create a USB boot Ubuntu with a Python environment for data analysis
How to create a serverless machine learning API with AWS Lambda
LaTeX and R (a little Python) environment construction with SublimeText3 (Windows)
[Pyenv] Building a python environment with ubuntu 16.04
Hello World and face detection with opencv-python 4.2
Create a Python function decorator with Class
Building a Python3 environment with Amazon Linux2
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
Create a python environment on your Mac