Until you run a Java program with the AWS SDK local to Windows

Premise

AWS SDK for Java 2.0 Developer Guide And what I'm trying to use this time.

pom.xml


    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <aws.java.sdk.version>2.11.12</aws.java.sdk.version>
    </properties>
<!--Omission-->
    <dependencies>
    	<dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>${aws.java.sdk.version}</version>
                <type>pom</type>
                <scope>import</scope>
    	</dependency>
    	<dependency>
    		<groupId>software.amazon.awssdk</groupId>
    		<artifactId>ecs</artifactId>
    		<version>${aws.java.sdk.version}</version>
    	</dependency>
    	<dependency>
    		<groupId>software.amazon.awssdk</groupId>
    		<artifactId>ssm</artifactId>
    		<version>${aws.java.sdk.version}</version>
    	</dependency>
    </dependencies>

Installation

Install the AWS CLI. Installing the AWS CLI version 2 on Windows

Configuration and Credential File Settings Make sure the files are under C: \ Users \ (username) \ .aws.

~/.aws/credentials


[default]
aws_access_key_id=(Own access_key_id)
aws_secret_access_key=(Own secret_access_key)

~/.aws/config


[default]
region=ap-northeast-1
output=json

Authentication preparation

Set up MFA in Assign MFA Device. After setting MFA, you can check and operate various services on the console only after logging out-> re-login. Check the authority to see information such as EC2 on the console.

Generate temporary authenticated users using MFA authentication

How do I use MFA tokens to authenticate access to AWS resources through the AWS CLI? ](Https://aws.amazon.com/jp/premiumsupport/knowledge-center/authenticate-mfa-cli/)

Checking MFA Status

The ARN in AWS for an SMS device, such as arn:aws:iam::123456789012:sms-mfa/username The ARN in AWS for a virtual device, such as arn:aws:iam::123456789012:mfa/username

This means the following.

C:\Users\works>aws sts get-session-token --serial-number arn:aws:iam::123456123456:mfa/[email protected] --token-code (6-digit MFA number) 

{
    "Credentials": {
        "AccessKeyId": "ASIA************",
        "SecretAccessKey": "p8j****************************",
        "SessionToken": "**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************",
        "Expiration": "2020-06-17T19:08:08+00:00"
    }
}

In this way you can get Credentials.

debug

How to switch AWS CLI settings and the difference between AWS_DEFAULT_PROFILE and AWS_PROFILE was easy to understand. ʻAws configure --profile As the profile name says, try creating a test profile ʻeclipse.

C:\Users\works>aws configure --profile eclipse
AWS Access Key ID [None]: (Credential Access Key ID)
AWS Secret Access Key [None]: (Credential Secret Access Key)
Default region name [None]: ap-northeast-1
Default output format [None]: json

with this ~/.aws/credentials ~/.aws/config Make sure that is updated.

This time, in this state, in the runtime environment variable of Eclipse ʻSet AWS_PROFILE = eclipse`.

The Java program worked locally safely. Related: Detailed notes such as coexistence of AWS SDKs 1 and 2

Recommended Posts

Until you run a Java program with the AWS SDK local to Windows
Submit a job to AWS Batch with Java (Eclipse)
Set a signed cookie (for CloudFront) with a custom policy using the AWS SDK for Java
Java program to resize a photo into a square with margins
How to reduce the load on the program even a little when combining characters with JAVA
Connecting to a database with Java (Part 1) Maybe the basic method
Replace with a value according to the match with a Java regular expression
[GCP] Until you push the local Docker image to the Container Registry
When I try to use the AWS SDK with Ruby + Lambda, `sam local` is messed up.
How to deal with the type that I thought about writing a Java program for 2 years
Get a list of S3 files with ListObjectsV2Request (AWS SDK for Java)
[Introduction to Java] How to write a Java program
Run a DMN with the Camunda DMN Engine
[Photo Organizer] [java] [windows] Move selected photos to a folder with 2 clicks
[AWS SDK for Java] Set a retry policy on the S3 client
I tried to make a program that searches for the target class from the process that is overloaded with Java
Validate the identity token of a user authenticated with AWS Cognito in Java
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
How to use Java framework with AWS Lambda! ??
Until you run the Apache Velocity sample code
Try debugging a Java program with VS Code
I tried to break a block with java (1)
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
How to save a file with the specified extension under the directory specified in Java to the list
You also need to specify the host when debugging remotely with Java 9 or later
What to do if you cannot execute with the command "Java package name / class name"
How to run the SpringBoot app as a service
[Tutorial] Download Eclipse → Run the application with Java (Pleiades)
How to deploy Java to AWS Lambda with Serverless Framework
I tried to operate SQS using AWS Java SDK
Export pdf with a single program (Java / Perl / VBA)
HTTPS connection with Java to the self-signed certificate server
Using the database (SQL Server 2014) from a Java program 2018/01/04
Credentials referenced by the AWS SDK for Java by default
[Java] How to start a new line with StringBuilder
Deploy a Java application developed locally with the Cloud Toolkit to an Alibaba Cloud ECS instance
Considering the adoption of Java language in the Reiwa era ~ How to choose a safe SDK
A memo of the program that allows you to realize that the probability of dice rolling is about 1/6
Until you build a project described in scala with Maven and execute it with the scala command.
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I made a program in Java that solves the traveling salesman problem with a genetic algorithm
How to take a screenshot with the Android Studio emulator
[Java] Change the process according to the situation with the Strategy pattern
Deploying a Java environment with Windows Subsystem for Linux (WSL)
I tried to create a java8 development environment with Chocolatey
I tried to modernize a Java EE application with OpenShift.
Add a local Swift Package to your project with Swift PM
[Beginner] Try to make a simple RPG game with Java ①
[Beginner] I made a program to sell cakes in Java
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
[Java] [Play Framework] Until the project is started with Gradle
Create a SlackBot with AWS lambda & API Gateway in Java
Create a method to return the tax rate in Java
How to deploy a kotlin (java) app on AWS fargate
Until you create a Web application with Servlet / JSP (Part 1)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
About the behavior when doing a file map with java
Try Spark Submit to EMR using AWS SDK for Java
A memorandum to reach the itchy place for Java Gold