# How do I store variables in S3 and access them from a KS test script?

**URL:** <https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [October 24, 2019, 8:52pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283 "2019-10-24T20:52:12Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric.martin](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/eric.martin/32/9109_2.png) [@eric.martin](https://forum.katalon.com/u/eric.martin)\
**Post date:** [October 24, 2019, 8:52pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/1 "2019-10-24T20:52:12Z")

</div>

I had a bit of a challenge presented to me. I need to store variables to be used in KS test scripts (such as e-mail addresses and passwords for logins) in S3 (for security reasons) and populate them into fields as the test script runs. Has anyone done this before? If so, I have no idea where to begin implementing something like this and could use some help. Storing them in the KS project itself is not an option (even with the built in password encryption), per the higher ups.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 24, 2019, 10:13pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/2 "2019-10-24T22:13:54Z")

</div>

You can mount a S3 Bucket as a Windows Drive using some tools installed on your PC. For example, quick search showed this:  
[https://tntdrive.com/mount-amazon-s3-bucket.aspx](https://tntdrive.com/mount-amazon-s3-bucket.aspx)

Once it is mounted, it is just a Windows drive (or a folder). You should be familiar with reading/writing files on it.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 24, 2019, 10:17pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/3 "2019-10-24T22:17:40Z")

</div>

You can try using AWS SDK for Java in Katalon Studio, though there could be a lot of hurdles for you to overcome. The following post shows one of the hurdles I encountered previously.

> [@Using AWS SDK in Katalon Studio, how to resolve external dependencies with Gradle](http://forum.katalon.com/t/using-aws-sdk-in-katalon-studio-how-to-resolve-external-dependencies-with-gradle/15696):
>
> I have made a demo project in GitHub. [GitHub - kazurayam/UsingAwsSdkInKatalonStudio: A katalon studio project. A test case calls AWS Java SDK for Amazon S3. External dependencies are resolved by using Gradle with com.katalon.gradle-plugin](https://github.com/kazurayam/UsingAwsSdkInKatalonStudio)Problems to solve (1) I want to use Amazon S3 in my test cases My [Visual Testing in Katalon Studio](http://forum.katalon.com/t/visual-testing-in-katalon-studio/13361) project enabled me to do visual regression testing. It compares 2 URLs of my AUT (production & development) visually in a time-slicing manner. Now I have a…

---

<div class="post-metadata">

**Author:** ![Stephanie.LovingJone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/stephanie.lovingjone/32/16104_2.png) [@Stephanie.LovingJone](https://forum.katalon.com/u/Stephanie.LovingJone)\
**Post date:** [April 27, 2023, 11:39pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/4 "2023-04-27T23:39:49Z")

</div>

Hello, I love this and thanks, but unfortunately I’m not familiar with how to code in Katalon writing/reading files to/from a folder, can you provide me an example of how to do that? I want to take the json file or text that I receive from an API response and write that to a S3 bucket, how do I code this in Katalon? Thanks in advance and I appreciate your help.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 28, 2023, 12:00am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/5 "2023-04-28T00:00:37Z")

</div>

> [@Stephanie.LovingJone](#):
>
> I’m not familiar with how to code in Katalon writing/reading files to/from a folder, can you provide me an example of how to do that?

A simple example:

```auto
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

import com.kms.katalon.core.configuration.RunConfiguration

Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path tmpDir = projectDir.resolve("tmp")
Files.createDirectories(tmpDir)
Path jsonFile = tmpDir.resolve("hero.json")

String jsonText = """{
   "name": "Shohei Ohtani",
   "team": "Los Angels Angels"
}"""

// write a text into file
File f = jsonFile.toFile()
f.text = jsonText

// read a file
String s = f.text
println s

```

 ![スクリーンショット 2023-04-28 9.03.30](https://europe1.discourse-cdn.com/katalon/original/3X/a/e/ae8ca45be16ecb1bdc4e6d5036f3f00498d2e3ae.jpeg)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 28, 2023, 12:07am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/6 "2023-04-28T00:07:50Z")

</div>

> [@Stephanie.LovingJone](#):
>
> and write that to a S3 bucket

If you are going to bother yourself working on AWS SDK, please go through the AWS tutorials first.

- [Amazon S3 Examples Using the AWS SDK for Java - AWS SDK for Java 1.x](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3.html)

Once you have got familiar with AWS SDK for S3, then you want to configure your Katalon Studio project so that it has all required extenal dependencies (jar files) in the `Drivers` folder. Katalon Studio does NOT support resolving dependencies for S3 out of box. You need to resolve it yourself. The following post explains how to do it.

[http://forum.katalon.com/t/using-aws-sdk-in-katalon-studio-how-to-resolve-external-dependencies-with-gradle/15696](http://forum.katalon.com/t/using-aws-sdk-in-katalon-studio-how-to-resolve-external-dependencies-with-gradle/15696)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 28, 2023, 1:20am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/7 "2023-04-28T01:20:35Z")

</div>

@Stephanie.LovingJone

Mounting Amazon S3 Bucket to make it accessible as a local directory would be an easier solution for you than using AWS SDK.

Search Google with key “mount S3 windows”, then you will find a lot of proposals. For example

> **[How to mount Amazon S3 Bucket as a Windows Drive. Map S3 Bucket to Windows...](https://tntdrive.com/mount-amazon-s3-bucket.aspx)**
>
> How to mount amazon s3 bucket as a windows drive. Map S3 Bucket to Windows Drive. Getting started guide.

The [TntDrive](https://tntdrive.com/mount-amazon-s3-bucket.aspx) possibly uses AWS SDK internally. It hides all complexities and it maps a directory of local file system to a S3 bucket so that you do not need to worry about the AWS SDK at all.

---

<div class="post-metadata">

**Author:** ![Stephanie.LovingJone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/stephanie.lovingjone/32/16104_2.png) [@Stephanie.LovingJone](https://forum.katalon.com/u/Stephanie.LovingJone)\
**Post date:** [April 28, 2023, 1:47am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/8 "2023-04-28T01:47:17Z")

</div>

WOW U ROCK!!! Thanks soooo much for this quick response, I will give your sample a try and provide feedback, this is exciting and I really do appreciate you, having these answers will definitely give me a jump start at completing this task for my team, thank you soooo much.

---

<div class="post-metadata">

**Author:** ![anon46315158](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@anon46315158](https://forum.katalon.com/u/anon46315158)\
**Post date:** [April 28, 2023, 8:19am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/9 "2023-04-28T08:19:27Z")

</div>

S3 buckets can be accesed also through REST API, see the quick guide:

> **[Amazon S3 REST API Introduction - Amazon Simple Storage Service](https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html)**
>
> Explains the Amazon S3 API operations, related request and response structures, and error codes to enable you to store data in the cloud.

It is not trivial, you will have to code first your own solution to sign the request.  
Katalon does not have support implemented for this.  
Start to read here on this matter:

> **[Authenticating Requests (AWS Signature Version 4) - Amazon Simple Storage...](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html)**
>
> Use access keys to create a signing key and authenticate your request using AWS Signature Version 4.

Luckily they provide also a java sample, should work as it is:

> **[Examples: Signature Calculations in AWS Signature Version 4 - Amazon Simple...](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-examples-using-sdks.html#sig-v4-examples-using-sdk-java)**
>
> Provides code samples of signature calculations written in Java and C# in AWS Signature Version 4.

Another way is, you can expose the S3 bucket as an NFS share.  
You have to setup an NFS Gateway first, see here:

> **[Create an NFS file share with custom configuration - AWS Storage Gateway](https://docs.aws.amazon.com/filegateway/latest/files3/CreatingAnNFSFileShare.html)**
>
> Create an NFS file share for a File Gateway.

Compared with the Windows Drive driver solution proposed before, mounting an NFS will work also on Linux and Mac systems so you can use that to execute the tests on whatever environment.

Alternate, you can setup a SMB (CIFS) share:

> **[Create an SMB file share with default settings - AWS Storage Gateway](https://docs.aws.amazon.com/filegateway/latest/files3/smb-fileshare-quickstart-settings.html)**
>
> Create an SMB file share with default settings

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 29, 2023, 9:33am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/10 "2023-04-29T09:33:14Z")

</div>

> [@Stephanie.LovingJone](#):
>
> this quick response

I have ever used the S3FS library. With it, I could let my Katalon Test case read/write to AWS S3 via `java.nio.file.Path` interface.

> **[GitHub - carlspring/s3fs-nio: A Java (NIO2) FileSystem Provider for Amazon...](https://github.com/carlspring/s3fs-nio)**
>
> A Java (NIO2) FileSystem Provider for Amazon AWS S3. - GitHub - carlspring/s3fs-nio: A Java (NIO2) FileSystem Provider for Amazon AWS S3.

I was successful.

> <https://github.com/kazurayam/materialstore/issues/118>
>
> Let me imagine that i want to develop an application on top of the "materialstor…e" on AWS. I would find it necessary to create a "store" on AWS S3.
> 
> How can I make it possible?
> 
> I want to develop an application runnable on EC2 with backing S3.

I am sure you can use it as well. You do not need to purchace products like TntDrive if you are capable to use the S3FS.

---

<div class="post-metadata">

**Author:** ![Stephanie.LovingJone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/stephanie.lovingjone/32/16104_2.png) [@Stephanie.LovingJone](https://forum.katalon.com/u/Stephanie.LovingJone)\
**Post date:** [May 2, 2023, 5:53pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/11 "2023-05-02T17:53:19Z")

</div>

This worked perfectly, wooo hooo, thanks again, now on to testing my Katalon script to read and write to my S3 bucket, lots of fun.

---

<div class="post-metadata">

**Author:** ![Stephanie.LovingJone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/stephanie.lovingjone/32/16104_2.png) [@Stephanie.LovingJone](https://forum.katalon.com/u/Stephanie.LovingJone)\
**Post date:** [May 2, 2023, 8:46pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/12 "2023-05-02T20:46:36Z")

</div>

Sorry, not sure how to declare the mapped path. Now that my S3 bucket is mapped to windows directory Z:\MyS3Bucket do I set it to a String and then re-declare it as a Path? The example is perfect because the getProjectDir is already declared, so what’s the syntax that I need to use for my Z:\MyS3Bucket? Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 2, 2023, 11:33pm UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/13 "2023-05-02T23:33:59Z")

</div>

> [@Stephanie.LovingJone](#):
>
> Now that my S3 bucket is mapped to windows directory Z:\MyS3Bucket do I set it to a String and then re-declare it as a Path?

Learn the following article for the Java8 Path API.

> **[Java NIO2 Path API | Baeldung](https://www.baeldung.com/java-nio-2-path)**
>
> A quick and practical guide to the Path API in Java

Possibly you want to write

```auto
Path dirMappedToS3 = Paths.get('Z:\MyS3Bucket')

```

---

<div class="post-metadata">

**Author:** ![Stephanie.LovingJone](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/stephanie.lovingjone/32/16104_2.png) [@Stephanie.LovingJone](https://forum.katalon.com/u/Stephanie.LovingJone)\
**Post date:** [May 3, 2023, 12:43am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/14 "2023-05-03T00:43:52Z")

</div>

Awesomeness, that did it, U ROCK AGAIN!!! You make this look so easy 🙂 thank you my friend

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 3, 2023, 12:46am UTC](https://forum.katalon.com/t/how-do-i-store-variables-in-s3-and-access-them-from-a-ks-test-script/35283/15 "2023-05-03T00:46:01Z")

</div>

> [@Stephanie.LovingJone](#):
>
> You make this look so easy

No, I don’t. AWS SDK does. AWS SDK is so well-designed that it performs perfect underneath the surface.
