Until INSERT S3 object into EC2 DB with Lambda @ java: AWS

This article is a memorandum from S3 to INSERT data to DB on EC2 via Lambda (java). (As of 09/2018) This is my first post, so please look at it with warm eyes. (You are welcome to point out. Please comment.)

1: AWS edition 2: Java part [Part 1] 3: Java [Part 2] 3.5: Java version [continued]

Creating an IAM user

Log in to the AWS Management Console and open the IAM dashboard.

Select "User" from the navigation bar on the left side of the screen. iam_01.png Create a user for S3 access from [Add User] at the top left of the screen. iam_02.png For later use, check "Programmatic access" in "Access type".

[Next step: Access authority] will take you to the access authority setting page, so select the block [Attach existing policy directly] on the right and select Filter the policy with "S3". iam_03.png

Some will be listed, so this time check the permissions for full access (read / wirte). Since the boundary is not set, go to the next step.

A confirmation screen will be displayed. After confirming that the user name and management policy are correct, click [Create User] at the bottom center of the screen to complete the creation of the user who has been granted the IAM role.

Create VPC and subnet

Let's create a VPC to which the EC2 instance belongs.

Access the VPC console. When you select [Create VPC] at the top of the screen, a pop-up will appear. Enter the VPC name (optional) and the IPv4 CIDR block. vpc_01.png Determine the address range according to the number of instances you need.

After you create your VPC, create a subnet within your VPC. Select "Subnet" from the navigation bar on the left side of the screen and click [Create Subnet] at the top. Enter the subnet name (optional), select the VPC you created earlier, and create a subnet.

Creating an internet gateway and attaching it to a VPC

Next, create an SSH entrance to connect to the created EC2 instance from the outside. Select "Internet Gateway" from the navigation bar of the VPC console. Similarly, click [Create Internet Gateway] from the top of the screen to create a gateway (Name tag is optional).

The gateway you just created is not tied to the VPC (not attached), so From [Action]-> "Attach to VPC", attach to the test_vpc created earlier. gw_01.png After attaching to the VPC, select "Route Table" from the navigation bar on the left side of the screen.

When you select the created VPC (test_vpc), the details of the VPC route information will be displayed at the bottom of the screen, so With the [Route] tab selected, click [Edit] to add a route.

Set the destination to 0.0.0.0/0 and move the cursor to the target, the gateway ID will be displayed, so click it. rtb_01.png Click [Save] to confirm the edit.

This completes the VPC area settings.

Creating an EC2 instance

Select Create Instance from the EC2 dashboard. Basically, it just pops according to the screen, but the specifications this time are as follows.

Instance type: t2.medium

OS disk File System vCPU Mem
RHEL 7.5 10GB xfs 2 cores 4GB

DB has installed SQL Server (Express).

Creating an S3 bucket

After connecting to the S3 management console, click [+ Create bucket] at the top left of the screen.

Proceed as follows according to the wizard.

S3_01.png The bucket name must be unique. This time, we will proceed with the defaults for ② and ③ of the wizard. S3_04.png After confirming that the input items are correct on the confirmation screen of ④, click [Create bucket]. Make sure the bucket was created successfully.

Next, let's upload an appropriate file with the [Upload] button at the top of the screen.

Here, the following CSV is created and uploaded.

test_people.csv


Id,Name,Age
1001,Dean,28
1002,Sam,25
1003,John,51
1004,Bobby,54
1005,Meg,26
csv_uploaded.png

Next time, I would like to get the information of this uploaded file by executing the Lambda function.

Summary

~~ (I forgot to take a capture) ~~ The EC2 part has been omitted. m (_ _) m The java edition will be posted soon.

Recommended Posts

Until INSERT S3 object into EC2 DB with Lambda @ java: AWS
Until INSERT S3 object into EC2 DB with Lambda @ java: Java [Continued]
Until you insert an S3 object into an EC2 DB with Lambda @ java: Java [Part 2]
Until you insert an S3 object into an EC2 DB with Lambda @ java: Java [Part 1]
AWS Lambda with Java starting now Part 1
[Java] When dealing with MySQL DB in Doma, insert Batch Insert into one
How to use Java framework with AWS Lambda! ??
How to deploy Java to AWS Lambda with Serverless Framework
Get S3 object size with AWS SDK for Ruby
Regularly post imaged tweets on Twitter with AWS Lambda + Java
Use Lambda Layers with Java
Try DB connection with Java
Build AWS Lambda with Quarkus
Java lambda expressions learned with Comparator
Hello World on AWS Lambda + Java
Deleting AWS S3 Objects in Java
Using Java with AWS Lambda-Eclipse Preparation
Getting started with Java lambda expressions
Get a list of S3 files with ListObjectsV2Request (AWS SDK for Java)