# How to work with Amazon S3?

**URL:** <https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194>\
**Category:** Module Development\
**Created:** [January 4, 2023, 1:05am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194 "2023-01-04T01:05:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [January 4, 2023, 1:05am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/1 "2023-01-04T01:05:52Z")

</div>

Hi Guys,

I am trying to store files to S3 by creating a module, by following SDK example [ignition-sdk-examples/scripting-function at master · inductiveautomation/ignition-sdk-examples · GitHub](https://github.com/inductiveautomation/ignition-sdk-examples/tree/master/scripting-function) I can use all scripts in designer.  
It shows error below:  
`software.amazon.awssdk.core.exception.SdkClientException: Unable to load an HTTP implementation from any provider in the chain. You must declare a dependency on an appropriate HTTP implementation or pass in an SdkHttpClient explicitly to the client builder.`

How can I work with S3 properly?  
Java code in script common project

> package com.inductiveautomation.ignition.examples.scripting;
> 
> import java.util.ArrayList;  
> import java.util.List;
> 
> import com.inductiveautomation.ignition.common.BundleUtil;  
> import com.inductiveautomation.ignition.common.script.hints.ScriptArg;  
> import com.inductiveautomation.ignition.common.script.hints.ScriptFunction;
> 
> import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;  
> import software.amazon.awssdk.auth.credentials.AwsCredentials;  
> import software.amazon.awssdk.services.s3.S3Client;  
> import software.amazon.awssdk.services.s3.model.ListBucketsResponse;
> 
> import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;  
> import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;  
> import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;  
> import software.amazon.awssdk.regions.Region;
> 
> public abstract class AbstractScriptModule implements MathBlackBox {
> 
> ```
> static {
> BundleUtil.get().addBundle(
> AbstractScriptModule.class.getSimpleName(),
> AbstractScriptModule.class.getClassLoader(),
> AbstractScriptModule.class.getName().replace('.', '/')
> );
> }
> 
> @Override
> @ScriptFunction(docBundlePrefix = "AbstractScriptModule")
> public int multiply2(
> @ScriptArg("arg0") int arg0,
> @ScriptArg("arg1") int arg1) {
> 
> return multiplyImpl(arg0, arg1);
> }
> 
> protected abstract int multiplyImpl(int arg0, int arg1);
> 
> @ScriptFunction(docBundlePrefix = "AbstractScriptModule")
> public String helloWorld(){
> return "Hi there!";
> }
> 
> @ScriptFunction(docBundlePrefix = "AbstractScriptModule")
> 
> ```
> 
> public List GetBuckets() {
> 
> String ACCESS\_KEY = "AKIA6FIM....FPSN";  
> String SECRET\_KEY = "QlliRmIATzF/ESX9.....bj9754ZbcL";  
> String BUCKET\_NAME = "files";  
> S3Client s3Client = S3Client.builder().region(Region.CA\_CENTRAL\_1).credentialsProvider(StaticCredentialsProvider  
> .create(AwsSessionCredentials.create(ACCESS\_KEY, SECRET\_KEY, ""))).build();  
> ListBucketsResponse listBucketsResponse = s3Client.listBuckets();
> 
> List res = new ArrayList();  
> listBucketsResponse.buckets().stream().forEach(x -\> res.add(x.name()));
> 
> return res;  
> }
> 
> }

Any ideas would be appreciated!

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [January 4, 2023, 2:41am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/2 "2023-01-04T02:41:11Z")

</div>

Hmm, it's issue of AWS.

```auto
S3Client s3Client = S3Client.builder().region(Region.CA_CENTRAL_1)
			.credentialsProvider(StaticCredentialsProvider.create(AwsSessionCredentials.create(ACCESS_KEY, SECRET_KEY, "")))
			.httpClient(UrlConnectionHttpClient.builder().build())
            .build();

```

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [January 4, 2023, 8:53am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/3 "2023-01-04T08:53:40Z")

</div>

Why following code is working on script console but not script panel when we bind to text?  
`import software.amazon.awssdk.regions.Region as Region;`

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 4, 2023, 10:46am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/4 "2023-01-04T10:46:27Z")

</div>

> [@weixionglichina](#):
>
> when we bind to text

What do you mean by this? Can we get an example?

Is there an exception message we can look at?

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [January 5, 2023, 1:52am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/5 "2023-01-05T01:52:03Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/81fe69ee2d4c425a8823803127ca9d7848bcfd04.png)

Error message is no module "software"

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 5, 2023, 2:53am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/6 "2023-01-05T02:53:12Z")

</div>

In the gateway, modules are installed into isolated classloaders--the contents are not exposed to the gateway as a whole. It works in the designer script console "by accident" because the designer (and vision clients) does not use more than one classloader.

To expose classes in the gateway, you must initialize script functions in script managers using the proper gateway hook.

---

<div class="post-metadata">

**Author:** ![weixionglichina](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weixionglichina/32/10650_2.png) [@weixionglichina](https://forum.inductiveautomation.com/u/weixionglichina)\
**Post date:** [January 5, 2023, 3:00am UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/7 "2023-01-05T03:00:20Z")

</div>

Got it! It made things more tougher. 😂

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 5, 2023, 1:28pm UTC](https://forum.inductiveautomation.com/t/how-to-work-with-amazon-s3/68194/8 "2023-01-05T13:28:59Z")

</div>

You can short-cut the process by exposing classes in fields instead of writing wrapper functions. In the class you register with the script manager, have lines like this:

```auto
public static final Class<?> AwsBasicCredentials = AwsBasicCredentials.class;
public static final Class<?> AwsCredentials = AwsCredentials.class;
public static final Class<?> S3Client = S3Client.class;
public static final Class<?> ListBucketsResponse = ListBucketsResponse.class;

```

If you register that as `system.amazon`, then your jython scripts can do this:

```auto
from system.amazon import AwsBasicCredentials, AwsCredentials, S3Client, ListBucketsResponse

```

😁
