If you use IRIS, the easiest and cleanest way to interact with AWS S3 is by using embedded Python and the boto3 library, which is the official AWS SDK for Python.

IRIS allows you to write class methods with Language = python, so you can write pure Python inside your ObjectScript classes. Here’s a simple example of listing objects in an S3 bucket:

Class MyApp.S3Utils
{

ClassMethod ListS3Objects(bucket As %String = "your-bucket-name") [ Language = python ]
{
    import boto3

    s3 = boto3.client("s3")
    response = s3.list_objects(Bucket=bucket,Prefix="your_folder")

    contents = response.get("Contents", [])
    for obj in contents:
        print("Key:", obj["Key"])
}

}

To call this method from ObjectScript:

Do ##class(MyApp.S3Utils).ListS3Objects("my-s3-bucket")

Just make sure the Python environment IRIS is using has boto3 installed:

pip install boto3

If you’re working with Ensemble, which doesn’t support embedded Python, you can still achieve the same result by calling a Python script externally using $ZF(-1):

Set cmd = "python3 /path/to/your_script.py"
Set status = $ZF(-1, cmd)

This way, you can keep the S3 logic in a Python script and still integrate it with Ensemble.

So the one-line non-deprecated way would be: 

    Set sc=person.%JSONExportToString(.json), dynObj = {}.%FromJSON(json)
    
    // or if we have long objects
    
    Set sc=person.%JSONExportToStream(.json), dynObj = {}.%FromJSON(json)

But I agree it would be nicer to have just one command!, like the one that @Laura Blázquez García pointed out. 

Good catch! I tried to keep it short, but it was too vague—my bad! Thanks for pointing it out! 😄 (I edited the article with your comments) . Thanks!

The CSPSystem user has probably been disabled because it has not been active for so long. You can connect to the terminal and use the ^SECURITY routine to display all the users and check the ones disabled. 

If this doesn't work and you need access quickly, contact the WRC. 

Just to be sure I understand, the VS Code - InterSystems Lite Terminal (based on web sockets) also has the Xecute limitations you mentioned. If so, can you give some examples of the limitations and what your terminal can do better? I guess other people will have the same questions (especially people who doesn't live on terminal 😅

Hey @Dmitry Maslennikov , awesome job!

Have you thought about using WebSockets with a simple HTML/JS setup for your terminal, as the VS Code extension does? If you've already tried that and moved on, I’d love to know why. If not, it’s a super easy approach, and I’m sure you’ll have it working in no time.

Just create a WebSocket connection:

const socket = new WebSocket("ws://localhost:8273/api/atelier/v8/%25SYS/terminal");

Then hook it into your terminal like this:

term.onData(data => socket.send(data)); // Send input to the server

I did some tests and got a working terminal. It’s not as smooth as VS Code Lite or yours, but it's close! Let me know if you want to dive deeper.

Thanks! 

Adding the self-signed certificate to the operating System's root certificates (in my case, the Mac keychain under System) worked.

Once the certificate was added, I didn't need to set http.proxyStrictSSL to false.

I think this is not working anymore. I tried installing the v2.12.6 but got the message that the extension is not available from Visual Studio Code for the Web 🙁

I am having this same problem and I am using the latest extension. 

I added the 

"http.proxyStrictSSL": false

to the User settings.json , which is the same as

But still getting the error: 
 

Check your server details in Settings (vgorillaaws[VGORILLA]).

request to https://ec2-x.x.x.x.us-east-2.compute.amazonaws.com/api/atelier/ failed, reason: self signed certificate

I am using [2.5.0] - 2024-05-02 InterSystems Language Server

Thanks! And nice tips and lovely explanation,  now everything is making more sense. 

Regarding the pure Python approach, I am still struggling with how to use it in a much simpler way. Your last example is still too complex for a very simple scenario of one or two python files. 

Let me explain. I have this class in the file hello_world.py

class HelloWorld:
    def sayhello(self):
        print("Hello, World!")
        return "you did it!"

Then I would like to use it doing something like: 

Class dc.boto Extends %RegisteredObject
{

ClassMethod test1() [ Language = python ]
{
    from hello_world import HelloWorld
    # Create an instance of HelloWorld
    greeting = HelloWorld()

    # Call the say_hello method
    ret=greeting.sayhello()
    print(ret)
}

ClassMethod test2()
{
    Set hello = ##class(%SYS.Python).Import("/iris-shared/python/hello_world.py")
    Write hello.sayhello()
}

}

But this is throwing ModuleNotFoundError errors. 

I don't know if I have to create a packet and import it with pip... if so, it will be still complex. 😌
Is this possible? Do you see my point?

I am not sure what you need or are looking for. If you want to list all the routines, you can do it by looping on the ^ROUTINE global. There are some other methods using System libraries to get this information. 

As a quick example, you can copy-paste the following code directly into the terminal to see if this is what you need: 

// In one line: 
SET routineName="" FOR  SET routineName=$ORDER(^ROUTINE(routineName)) QUIT:routineName=""  WRITE routineName, !

// More readable: 
SET routineName = ""
FOR {
    SET routineName = $ORDER(^ROUTINE(routineName))
    QUIT:routineName=""
    WRITE routineName, !
}

Great article!

I've gained a clearer understanding after reading it. However, I'm struggling a bit with your example. It seems a bit complex, especially for those of us who are new to integrating ObjectScript with custom Python classes and routines. A more straightforward example would be really helpful.

Your code particularly draws attention to the use of this class:

ClassMethod GetPythonInstance(
	pModule,
	pRemoteClassname) As %SYS.Python
{
    set importlib = ##class(%SYS.Python).Import("importlib")
    set builtins = ##class(%SYS.Python).Import("builtins")
    set sys = ##class(%SYS.Python).Import("sys")

    set module = importlib."import_module"(pModule)
    do importlib."reload"(module)

    set class = builtins.getattr(module, pRemoteClassname)
    return class."__new__"(class)
}
 

Could you elaborate on the rationale behind this specific structure, particularly the inclusion of builtins, importlib, and sys? Is there a simpler alternative you might suggest?

In my own projects, I've been using embedded Python with the Python tag, which usually is enough due to its simplicity and speed. However, as you mentioned, it lacks certain features. Eventually, I end up with numerous embedded functions, repeatedly importing the same libraries for each method, which looks cluttered. See:
 

ClassMethod moveFile() [ Language = python ]
{
    import boto3,iris
    # do stuff
}

ClassMethod getFile() [ Language = python ]
{
    import boto3,iris,json,datetime
    # do stuff
}


At this juncture, adopting your strategy to transfer all code to a .py file (not as a class) seems like a viable option, then accessing these methods via ObjectScript. I'm inclined to avoid Python classes due to their complexity and the need for instantiation. I prefer using functions for their simplicity and ease of understanding. What would you recommend in this scenario? How would calling code looks like? 
 

These warnings suggest a performance problem with the CPU and disk bottlenecks. 

If you are running very intensive processes, you should see these warnings go away after they finish. However, if you keep seeing them continuously, I recommend going deeper and analyzing the performance. 

Analyzing the performance takes time, and it's not always easy for non-experts. There is a great series of articles written in this community that can help with this: 

https://community.intersystems.com/post/intersystems-data-platforms-cap…

If you don't want to go through all these series and can easily increase the system resources, it would be an easy way to probe and solve the problem ;-). What I mean by increasing system resources is by adding more CPUs and faster disks. Nowadays, with Virtual machines and cloud systems, this is quite simple. 

And let me insist again, if this is a production system, you may want to open a WRC problem for extra help. Having the disk too stressed will end in User/Application pauses. 

Ups! I just realized you wrote the system is Caché and not Iris. So, instead of the messages.log, you should read cconsole.log. Instead of ^SystemCheck, it would be ^Buttons, and, instead of ^PerformanceCheck, it will be ^pButtons. 

This is not a nice error to see in a production environment. If this is a production site, I recommend contacting the Support department. 

To find the problem, you can look at the messages.log. There should be an error written with more details.

Most of the time, these errors are related to disk permissions or disk stress. Tools like ^SystemCheck and/or ^SystemPerformance will gather the required information to diagnose the problem. If you contact Support, they will probably ask for this. 

As it is not a class method you need either to create/open an object for the class or rewrite the method as ClassMethod (instead of Method). But as the SetSensor call is also pointing to the same object (See do ..SetSensor), the simplest would be to create/open the object:

set obj=##class(Package.YourClass).%New()
do obj.ResponseTimeCurrentMonth("USER")

You may also need to add some Writes to the terminal to see something. For example:

write  !,"Date:",InDate
write  !, "time taken:",timeTaken


    

To me, the simplest is CSP. You require an HTML file with some Server Side code, and you already have some samples.

A more modern (but also simple) would be REST. You require a little extra setup with ObjectScript class (To handle the REST) + HTML code + Javascript Code to call the rest pages. 

They look very old! So they may not be used anymore and could be removed (report it internally). 

I must say that I hardly remember a Wizard to import XML/WDSL where you could see the World icon... but I may be wrong as my memory is quite bad ;-)

Hi Andy, 

If you have problems with production servers, I advise contacting Support directly. (Looking at the question's date, you may have contacted us already).

The issue you show here is not common and can be related to file permissions (reinstalling may help) or a product bug. To diagnose the problem, Support may need to ask you for more details, logs, etc. 

I am a little surprised you asked this :-P ..... and the answer, as you can imagine, is using the magical $Z functions! 

In this case, searching a little you can find: 

$ZISWIDE (ObjectScript)

Checks whether a string contains any 16-bit wide characters. 

See: 

https://docs.intersystems.com/iris20221/csp/docbook/Doc.View.cls?KEY=RC…

I think playing with other functions could give you what we are looking for here.

Therefore, now that we have a utility that can check if something is Unicode or not, the rest would be to do a routine to read all the globals and check for the content with this function. I have seen routines getting all the globals and looping before but don't have it handy.

This programmatic way of looping and checking all the globals gives you more control and allows you to find where there is something not expected. But, as it takes some time to write if the original question is something you just want to do once, a backup + restore seems quicker and simpler.

There isn't any flag telling whether a database is Unicode or not inside the database file. If a Unicode database has no UNICODE characters, it will be accessible by an 8-bit version without problems. 

If you want to know if a database has wide characters (Unicode chars), you could try to read all the globals inside an 8-bits instance and wait for a <WIDE CHAR> error. In order to read all the globals, there are several alternatives, like building a small routine, doing a backup and/or restore, exporting/importing globals, etc. Of course, there are more elegant ways to check the globals and data than expecting an error. 

Kevin, 

You should run it over the weekend, if the system is busy, the operation may take longer or not fully complete. 

See notes from the documentation: 

Compacting a Database

The compact database operation is designed to run concurrently with normal database activity. The operation does consume some system resources, however, and may not complete if the system is under extremely high load. For these reasons, InterSystems recommends running this and other database reorganization operations (including compacting and defragmenting globals) during off-peak hours, and running only one such operation on a system at a time.

Thanks a lot! 

That was my intention, trying to show something as simple as possible so anyone can look inside and adapt the code to what they need. 

To make it simpler I could have used the API methods and calls provided by default, but I preferred to "hack"  those methods to allow restore where I wanted without requesting any prompt and finally running the Integrity check with multiple process. This also allow me to control the return of the integrity report and execute an IF to check if there was an error or not. 

I was logging to the messages.log (which is also displayed in the docker logs) just in case you prefer to run it not interactively or in a docker up session. You can of course leave the instance up and call the method. 

I didn't want to spend much time in the way of calling the docker instance as I am sure that in a real environment most of the customers will have to write a script moving or renaming the .cbk files and executing the app.

So you didn't find another simpler alternatives to  %ConvertJSONToObject  from the %ZEN package? 

I will report to my colleagues from development, as not sure using %ZEN is the best way to do this. 

Thanks

Mario