What to use WMI(Windows Management Instrumentation) from remote Linux server?



Usually, I can access and run some command with SSH. In this case, I used "Paramiko" module. This is sample code which I create. However, I have some questions from here. It is if is possible to access and run some command with RDP. At this time. I can not found any solution for this. But I have found about "WMI (Windows Management Instrucmentation)". It make I can get some information which is offered by Window OS with WMI.


1. Install python-wmi-client-wrapper.


In this "Git", there is the way how to installation for this


pip install wmi-client-wrapper 


2. Install WMI


"WMI" is the package for Window OS. Therefore, the wrapper is necessary. The first step is to obtain these wrapper. Thus, I still need "WMI" main module. In my case, I used Ubuntu 16.04 LTS, and I will install WMI 1.3.16.


ulimit -n 100000

cd /tmp

mkdir wmic

cd wmic


apt install autoconf gcc libdatetime-perl make build-essential g++ python-dev

wget http://www.opsview.com/sites/default/files/wmi-1.3.16.tar_.bz2

bunzip2 wmi-1.3.16.tar_.bz2

tar -xvf wmi-1.3.16.tar_

cd wmi-1.3.16/


After above, I need edit some line of file to make and build this WMI.


vim Samba/source/pidl/pidl

:583 (to jump to line 583)

remove the word defined before @$pidl

:wq

========= Look here =============
$pidl = Parse::Pidl::IDL::parse_file($idl_file, \@opt_incdirs);
defined @$pidl || die "Failed to parse $idl_file";  >>>> @$pidl || die "Failed to parse $idl_file";
require Parse::Pidl::Typelist;
=============================


And I need export some values also.


export ZENHOME=/usr

make "CPP=gcc -E -ffreestanding"

cp Samba/source/bin/wmic /bin


Now, I can use WMI and WMI-wrapper. From now, I will do some sample code. 


3. Create the sample code.


I will create some sample code to obtain the Window Processor Information.


import wmi_client_wrapper as wmi


wmic = wmi.WmiClientWrapper(

    username="Administrator",

    password="password",

    host="172.22.0.123",

)


output = wmic.query("SELECT * FROM Win32_Processor")


After run this command, I will get some result with JSON format.


# ./sample.py

[{'L2CacheSize': '0', 'VMMonitorModeExtensions': False, 'ConfigManagerErrorCode': '0', 'VoltageCaps': '0', 'PowerManagementSupported': False, 'LoadPercentage': '12', 'SerialNumber': '', 'ThreadCount': '0', 'Version': '', 'MaxClockSpeed': '2400', 'CpuStatus': '1', 'PartNumber': '', 'SecondLevelAddressTranslationExtensions': False, 'Revision': '16130', 'Status': 'OK', 'PNPDeviceID': None, 'L2CacheSpeed': '0', 'AddressWidth': '64', 'ConfigManagerUserConfig': False, 'ErrorCleared': False, 'ProcessorId': '1789FBFF000306F2', 'ProcessorType': '3', 'DeviceID': 'CPU0', 'CurrentVoltage': '0', 'CurrentClockSpeed': '2400', 'Manufacturer': 'GenuineIntel', 'Name': 'Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz', 'InstallDate': None, 'Level': '6', 'AssetTag': '', 'SocketDesignation': 'CPU 1', 'NumberOfCores': '1', 'Caption': 'Intel64 Family 6 Model 63 Stepping 2', 'StatusInfo': '3', 'Architecture': '9', 'UniqueId': None, 'PowerManagementCapabilities': 'NULL', 'OtherFamilyDescription': None, 'Description': 'Intel64 Family 6 Model 63 Stepping 2', 'CreationClassName': 'Win32_Processor', 'NumberOfLogicalProcessors': '1', 'Family': '5', 'ErrorDescription': None, 'Characteristics': '2816', 'UpgradeMethod': '1', 'SystemName': 'EC2AMAZ-JC32MSV', 'NumberOfEnabledCore': '108', 'LastErrorCode': '0', 'ExtClock': '0', 'Stepping': None, 'VirtualizationFirmwareEnabled': False, 'Role': 'CPU', 'L3CacheSize': '0', 'L3CacheSpeed': '0', 'Availability': '3', 'SystemCreationClassName': 'Win32_ComputerSystem', 'DataWidth': '64'}]


4. Troubleshooting


During I try this, I do not open any security rule for this. I am question for this. I want to know if what port is used for this running. I dump the packet on my host. "135" Port are used. This port is RPC for Window. It is default opened.


04:19:44.298786 IP 172.22.0.216.46372 > 172.22.0.123.135: Flags [S], seq 2010311507, win 26883, options [mss 8961,sackOK,TS val 2762852 ecr 0,nop,wscale 7], length 0

04:19:44.299089 IP 172.22.0.123.135 > 172.22.0.216.46372: Flags [S.], seq 1265146297, ack 2010311508, win 8192, options [mss 8961,nop,w cale 8,sackOK,TS val 1122704139 ecr 2762852], length 0

04:19:44.299098 IP 172.22.0.216.46372 > 172.22.0.123.135: Flags [.], ack 1, win 211, options [nop,nop,TS val 2762853 ecr 1122704139], length 0


I run "netstat -an" on Window. The result is look like below.


  TCP    172.22.0.123:59796     52.23.123.168:443      ESTABLISHED

  TCP    172.22.0.123:60018     198.252.206.25:443     ESTABLISHED

  TCP    [::]:135               [::]:0                 LISTENING

  TCP    [::]:445               [::]:0                 LISTENING 


Reference 


[ 1 ] https://www.shellandco.net/wmic-command-ubuntu-16-04-lts/

[ 2 ] https://askubuntu.com/questions/885407/installing-wmic-on-ubuntu-16-04-lts

[ 3 ] https://github.com/kanzure/python-wmi-client-wrapper



How to Install AWS JAVA SDK in Ubuntu 16.04


In this post, I write the installation for AWS JAVA SDK. I followed this documentation 


1. Install the latest Oracle JAVA JDK.


I need to download "Oracle JAVA JDK" from here. I will install the JDK. JDK includes the JRE. In my case, I create "javase" directory where I download and extract downloaded file on. And I used "wget" command with options "--no-check-certificate" to obtain from download link.


# mkdir javase

# cd javase

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.tar.gz 


# tar xvfz jdk-10.0.2_linux-x64_bin.tar.gz


The extracted files are not for installation. They are the files to run and use. Therefore, I need to edit my ".bashrc". In my case, "java" and "javac" files are located in "/home/ubuntu/javase/jdk-10.0.2/bin". 


cat /home/ubuntu/.bashrc

# export PATH=$PATH:/home/ubuntu/javase/jdk-10.0.2/bin

source /home/ubuntu/.bashrc


Now, I can use the Oracle JDK. "java --version" show the version information.

 

# java --version

java 10.0.2 2018-07-17

Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)

Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)


And I also create sample code, "sample.java", in different directory. In my case, I create another directory which name is "projects". I write like below.   


# mkdir -p /home/ubuntu/projects

# vi Sample.java

package com.sample;


class Sample {

     public static void main(String[] args){

           System.out.println("Hello, JAVA");

     }

}


And compile and run the sample code, "javac -d . Sample.java". I used option "-d" because I defined the package in the sample code. After compile, I can confirm "Sample.class" file is located on that directory. And Run it.


# javac -d . Sample.java

# ls com/sample/Sample.class

com/sample/Sample.class


# java com/sample/Sample

Hello, JAVA


Now, I can do JAVA programming.


2. Set up for the AWS SDK.


I still can not use the AWS SDK, now. In this part, I will follow some instruction to setup for the AWS SDK. In this documentation, I need to choose builder, In my case I select "Apache Maven". To use the SDK with Apache Maven, I need to have Maven installed.


2-1. Download, Install and Run Maven


I follow in this documentation. I make directory for Maven, And Download and extract it.


# mkdir apache-mavena

# cd apache-mavena

# wget http://apache.tt.co.kr/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz

tar xvfz apache-maven-3.5.4-bin.tar.gz

 

In my case, "bin" is located in "/home/ubuntu/apache-maven/apache-maven-3.5.4/bin". I will add this path in my ".bashrc" file.


cat /home/ubuntu/.bashrc

export PATH=$PATH:~/.local/bin:/home/ubuntu/javase/jdk-10.0.2/bin:/home/ubuntu/apache-maven/apache-maven-3.5.4/bin

source /home/ubuntu/.bashrc


Now, I can confirm the version for marven with "mvn -v" command


# mvn -v

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)

Maven home: /home/ubuntu/apache-maven/apache-maven-3.5.4

Java version: 10.0.2, vendor: Oracle Corporation, runtime: /home/ubuntu/javase/jdk-10.0.2

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "4.4.0-1066-aws", arch: "amd64", family: "unix"


I think I prepare to use this. I will follow the rest of the instructions. 


2-2. Create a new Maven package


In this documentation, it shows Maven Archetype. I think this is similar with "create projects" of other program languages. 


# cd projects/

# mvn -B archetype:generate \

  -DarchetypeGroupId=org.apache.maven.archetypes \

  -DgroupId=com.sample.myapps \

  -DartifactId=app


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 54.510 s
[INFO] Finished at: 2018-09-12T21:02:15Z
[INFO] ------------------------------------------------------------------------

# ls -la app/
total 16
drwxr-xr-x 3 root root 4096 Sep 12 21:02 .
drwxr-xr-x 3 root root 4096 Sep 12 21:02 ..
-rw-r--r-- 1 root root  636 Sep 12 21:02 pom.xml
drwxr-xr-x 4 root root 4096 Sep 12 21:02 src


After run command above, I can see the "app" directory. In this directory, "pom.xml" and "src" directory are located. And I also can confirm there is "App.java" file under "/src/main/java/com/sample/myapps". To use the AWS SDK for Java in my project, I need to declare it in "pom.xml" file. In my case, I want to entire AWS SDK. Therefore I will add like below. (I can see the latest version in this document


# vi app/pom.xml

  <dependencies>

    <dependency>

      ....................

    </dependency>

    <dependency>

      <groupId>com.amazonaws</groupId>

      <artifactId>aws-java-sdk</artifactId>

      <version>1.11.407</version>

    </dependency>

  </dependencies>

</project>

ckag


Now, I configure to use AWS entire SDK. I can build if my configuration is correct or not with "mvn package". This command is for building the project.


# cd app/

# mvn package


After run command, I can see the AWS SDK downloaded. Please, note, you can meet some error "Source option 5 is no longer supported. Use 6 or later." and build fail. I solved this issue with adding 


# vi pom.xml

  <properties>

    <maven.compiler.source>1.6</maven.compiler.source>

    <maven.compiler.target>1.6</maven.compiler.target>

  </properties>


Now. Let's try to make some code. However, I have some question. "where is the main function to start coding?". In my case, main file is located in "./app/src/main/java/com/sample/myapps/App.java". Look at the this file.

vi app/src/main/java/com/sample/myapps/App.java

package com.sample.myapps;


/**

 * Hello world!

 *

 */

public class App

{

    public static void main( String[] args )

    {

        System.out.println( "Hello World!" );

    }

}



I have already built with this source. I can see the "class" file in the "/target/classes".

ls app/target/classes/com/sample/myapps/App.class

app/target/classes/com/sample/myapps/App.class


Thus, I can run this file. But I do not know how it is possible with command. 

mvn exec:java -Dexec.mainClass=com.sample.myapps.App


INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ app ---

Hello World!

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS


Look!, I get the result. It's works now. If you meet some error, please do mvn with "clean" and "compile" again.

mvn clean

# mvn compile


I used "mvn exec:java -Dexec.mainClass=com.sample.myapps.App" command with some option. It is not simple to re-write. Therefore, I can add some plugin in the pom.xml. I add "<build><plugins></plugins></build>"

# cat pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.sample.myapps</groupId>

  <artifactId>app</artifactId>

  <packaging>jar</packaging>

  <version>1.0-SNAPSHOT</version>

  <name>app</name>

  <url>http://maven.apache.org</url>

  <properties>

    <maven.compiler.source>1.6</maven.compiler.source>

    <maven.compiler.target>1.6</maven.compiler.target>

  </properties>

  <dependencies>

    ........................................................

  </dependencies>

  <build>

    <plugins>

    <plugin>

        <groupId>org.codehaus.mojo</groupId>

        <artifactId>exec-maven-plugin</artifactId>

        <version>1.2.1</version>

        <executions>

            <execution>

                <goals>

                    <goal>java</goal>

                </goals>

            </execution>

        </executions>

        <configuration>

            <mainClass>com.sample.myapps.App</mainClass>

        </configuration>

    </plugin>

    </plugins>

  </build>

</project>


Now I can run without the option.

mvn exec:java



In this documentation, this shows 5 ways to obtain the credential. 

1. Environment variables–AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. 
2. Java system properties–aws.accessKeyId and aws.secretKey. 
3. The default credential profiles file– typically located at ~/.aws/credentials 
4. Amazon ECS container credentials
5. Instance profile credentials

These method has different class each to use. In this documentation, it shows how to setup for 1 and 3 above. I will use the "S3 list bucket" as sample code for this test. The sameple code is here. I copied and pasted in App.java.

vi src/main/java/com/sample/myapps/App.java

package com.sample.myapps;


import com.amazonaws.services.s3.AmazonS3;

import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import com.amazonaws.services.s3.model.Bucket;

import java.util.List;


public class App

{

    public static void main( String[] args )

    {

        final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();

        List<Bucket> buckets = s3.listBuckets();

        System.out.println("Your Amazon S3 buckets are:");

        for (Bucket b : buckets) {

           System.out.println("* " + b.getName());

        }

    }

}


# mvn clean compile

# mvn exec:java


Someone can get some error like below. There are several reasons. One of reasons is "credential" issue. Thus, my application does not get the correct credential information.

"InvocationTargetException: Failed to parse XML document with handler class com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser$ListAllMyBucketsHandler: The entity "ntilde" was referenced, but not declared."

Look at this documentation. I think my sample code try to use environment variable. So I need to export some parameters like below.

export AWS_ACCESS_KEY_ID=xxxxxx

# export AWS_SECRET_ACCESS_KEY=xxxx

# export AWS_REGION=ap-northeast-2


After add this values, run "mvn exec:java". I can get finally the results.

mvn exec:java

Your Amazon S3 buckets are:

* cf-templates-16hzoxi2ozb3b-ap-northeast-1


At this time, I try to run with "~/.aws/credential" and "~/.aws/config". I add "[s3with]" on each like below. To use this profile, I need to export some values. I can see the some error messages like "InvocationTargetException: profile file cannot be null ".

# vi ~/.aws/credentials

[default]

aws_access_key_id=xxxxx

aws_secret_access_key=xxxxxxx


[s3with]

aws_access_key_id=yyyyyy

aws_secret_access_key=yyyyy


# vi ~/.aws/config

[default]

region=zzzzz


[s3with]

region=ap-northeast-2


# export AWS_PROFILE=s3with

# export AWS_CREDENTIAL_PROFILES_FILE=/home/ubuntu/.aws/credentials


Now, I need revise sample code. Please, note, I import more, "import com.amazonaws.auth.profile.ProfileCredentialsProvider;" and "import com.amazonaws.regions.Regions;".

## cat src/main/java/com/sample/myapps/App.java

package com.sample.myapps;


import com.amazonaws.services.s3.AmazonS3;

import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import com.amazonaws.services.s3.model.Bucket;

import com.amazonaws.auth.profile.ProfileCredentialsProvider;

import com.amazonaws.regions.Regions;

import java.util.List;


public class App

{

    public static void main( String[] args )

    {

        final AmazonS3 s3 = AmazonS3ClientBuilder.standard()

                        .withRegion(Regions.AP_NORTHEAST_2)

                        .withCredentials(new ProfileCredentialsProvider("s3with"))

                        .build();

        List<Bucket> buckets = s3.listBuckets();

        System.out.println("Your Amazon S3 buckets are:");

        for (Bucket b : buckets) {

           System.out.println("* " + b.getName());

        }

    }

}


Now, Also I can get the results again. Another method is insert the credential into the code with "BasicAWSCredentials" and "AWSStaticCredentialsProvider"

import com.amazonaws.auth.BasicAWSCredentials;

import com.amazonaws.auth.AWSStaticCredentialsProvider;


And the sample code should be re-write like below.

# cat src/main/java/com/sample/myapps/App.java

package com.sample.myapps;


import com.amazonaws.services.s3.AmazonS3;

import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import com.amazonaws.services.s3.model.Bucket;

import com.amazonaws.auth.BasicAWSCredentials;

import com.amazonaws.auth.AWSStaticCredentialsProvider;

import java.util.List;


public class App

{

    public static void main( String[] args )

    {

        BasicAWSCredentials awsCreds = new BasicAWSCredentials("xxxxx", "xxxxx");

        final AmazonS3 s3 = AmazonS3ClientBuilder.standard()

                        .withRegion(Regions.AP_NORTHEAST_2)

                        .withCredentials(new AWSStaticCredentialsProvider(awsCreds))

                        .build();

        List<Bucket> buckets = s3.listBuckets();

        System.out.println("Your Amazon S3 buckets are:");

        for (Bucket b : buckets) {

           System.out.println("* " + b.getName());

        }

    }

}


So far, I use profile for Credentials. And I use the static method for Region. I am some question for this. Is there anyway to use the profile for this Region field. "AwsProfileRegionProvider;" class offer it.


## cat src/main/java/com/sample/myapps/App.java

package com.sample.myapps;


import com.amazonaws.services.s3.AmazonS3;

import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import com.amazonaws.services.s3.model.Bucket;


import com.amazonaws.auth.profile.ProfileCredentialsProvider;

import com.amazonaws.regions.AwsProfileRegionProvider;

import java.util.List;


public class App

{

    public static void main( String[] args )

    {


        AwsProfileRegionProvider r = new AwsProfileRegionProvider("s3with");

        String rs = r.getRegion();


        final AmazonS3 s3 = AmazonS3ClientBuilder.standard()

                        .withRegion(rs)

                        .withCredentials(new ProfileCredentialsProvider("s3with"))

                        .build();

        List<Bucket> buckets = s3.listBuckets();

        System.out.println("Your Amazon S3 buckets are:");

        for (Bucket b : buckets) {

           System.out.println("* " + b.getName());

        }


    }

}


# mvn clean compile

# mvn exec:java


So, Now, I can get the information about credential and reason with the profile. Please, note, I have define the information on "credentials" and "config". I need to add some Environment like below.


export AWS_CONFIG_FILE=/home/ubuntu/.aws/config 

# export AWS_CREDENTIAL_PROFILES_FILE=/home/ubuntu/.aws/credentials


If I am necessary, I can add these over my ".bashrc" file. Now, Enjoy the JAVA coding.



Reference 


[ 1 ] https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-install.html

[ 2 ] https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-project-maven.html

[ 3 ] https://maven.apache.org/index.html

[ 4 ] http://maven.apache.org/archetypes/maven-archetype-quickstart/

[ 5 ] https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bom

[ 6 ] https://github.com/spring-guides/gs-maven/issues/21

[ 7 ] https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html

[ 8 ] https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html

[ 9 ] https://stackoverflow.com/questions/19850956/maven-java-the-parameters-mainclass-for-goal-org-codehaus-mojoexec-maven-p

[ 10 ] https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html?com/amazonaws/auth/profile/ProfileCredentialsProvider.html

How to Upload Object into S3 with multipart-upload using S3 API CLI


In this post, I will reproduce how to upload object with multipart. I can use the "awscli s3api" command for this. Before I study, I though AWS did all of process such as split, upload and resemble. However, it is not. (I am not sure if SDK can do all of these). I will write from split to complete multipart-upload.


1. Split object


Before upload object, I need to split object by the size which I want to upload. In my case, I define almost 40MB. And "split" command is used to split object by specific size. "split -b 40000000 sample/TWICE「BDZ」Music\ Video.mp4 splited" means that the "sample/TWICE「BDZ」Music\ Video.mp4" file will be splite by the size and the splited file names are prefixed with "splited". Therefore, I can see the 2 file which splited.


# split -b 40000000 sample/TWICE「BDZ」Music\ Video.mp4 splited


# ls -la spliteda*

-rw-r--r-- 1 root root 40000000 Sep 11 09:52 splitedaa

-rw-r--r-- 1 root root 21067922 Sep 11 09:52 splitedab


I will upload these files with multipart-upload.


2. Create Multipart-Upload


There are several stpes to use multipart-upload. At first, I create multi-part upload. This step will notice to S3 that I have something with large size to upload.


# aws s3api create-multipart-upload --bucket s3-multistore-bucket --key 'TWICE「BDZ」Music Video.mp4'

{

    "Bucket": "s3-multistore-bucket",

    "UploadId": "j.kLRorRoj1WEDV9iH1jrIeee5KETBL3raUH5odcycSxsl0RZY4p9Q.WK04lL9c7tsUxmDXwGEHwVlgm_MR.La4IHkM1M5xNQrCXossn5L_nXKJ0v.9_B3mNbL8GSoE8WBToEMPfELYF3VPh3g5PHg--",

    "Key": "TWICE「BDZ」Music Video.mp4"

}


After run this command, I can get "UploadId". Please note this value. This value will be used for next steps.


3. Upload-part


So far, any file is not uploaded. I need to upload these splited files with upload-part command. In this command, there are 2 options which I need to focus. They are "upload-id" and "part-number". "upload-id" is kind of the credential. "part-number" is the sequential value to assemble at end of process.


# aws s3api upload-part --bucket s3-multistore-bucket --key 'TWICE「BDZ」Music Video.mp4' --part-number 1 --body splitedaa --upload-id  "j.kLRorRoj1WEDV9iH1jrIeee5KETBL3raUH5odcycSxsl0RZY4p9Q.WK04lL9c7tsUxmDXwGEHwVlgm_MR.La4IHkM1M5xNQrCXossn5L_nXKJ0v.9_B3mNbL8GSoE8WBToEMPfELYF3VPh3g5PHg--"

{

    "ETag": "\"45de77ba3c71c3105a358971b7464b5a\""

}

root@ip-172-22-1-179:~# aws s3api upload-part --bucket s3-multistore-bucket --key 'TWICE「BDZ」Music Video.mp4' --part-number 2 --body splitedab --upload-id  "j.kLRorRoj1WEDV9iH1jrIeee5KETBL3raUH5odcycSxsl0RZY4p9Q.WK04lL9c7tsUxmDXwGEHwVlgm_MR.La4IHkM1M5xNQrCXossn5L_nXKJ0v.9_B3mNbL8GSoE8WBToEMPfELYF3VPh3g5PHg--"

{

    "ETag": "\"7fa82dacd6f59e523e60058660e1ab6f\""

}


I uploaded 2 files into S3. However, I can not see the S3 GUI. Because it is not completed object yet. So I need to finish this process.


4. Create "multipart" file


I have some questions. How does AWS know the order to assemble to make single object. I have already known there is part-number. However, this information is only used to mark this object. AWS can not know what is the begining and last. Because of this, I need to create "multipart" file to define single object. In this manual, there is format for this file.


# vi multipart.file

{

 "Parts":[

   {

      "ETag": "\"45de77ba3c71c3105a358971b7464b5a\"",

      "PartNumber" : 1

   },

   {

      "ETag": "\"7fa82dacd6f59e523e60058660e1ab6f\"",

      "PartNumber" : 2

   }

 ]

}


Now, I am ready to finish these multipart upload.


5. Complete multipart upload


I will run command "complet-multipart-upload" to finish all of process.


# aws s3api complete-multipart-upload --multipart-upload file://multipart.file --bucket s3-multistore-bucket --key 'TWICE「BDZ」Music Video.mp4' --upload-id j.kLRorRoj1WEDV9iH1jrIeee5KETBL3raUH5odcycSxsl0RZY4p9Q.WK04lL9c7tsUxmDXwGEHwVlgm_MR.La4IHkM1M5xNQrCXossn5L_nXKJ0v.9_B3mNbL8GSoE8WBToEMPfELYF3VPh3g5PHg--

{

    "ETag": "\"a1a27863cd20501d3e564e10b461d99f-2\"",

    "Bucket": "s3-multistore-bucket",

    "Location": "https://s3-multistore-bucket.s3.ap-northeast-2.amazonaws.com/TWICE%E3%80%8CBDZ%E3%80%8DMusic+Video.mp4",

    "Key": "TWICE「BDZ」Music Video.mp4"

}


Now, I can see this object on S3 GUI. Look at the "ETag", there is "-2". This means the object are uploaded with multipart-uplad and the splited objects was 2. This is the reason why the "ETag" of some objects is not matched. 


Reference


[ 1 ] https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html

[ 2 ] https://www.computerhope.com/unix/usplit.htm

+ Recent posts