Encontrar

記事
· 2024年5月3日 6m read

Demo: Connecting Locally to an S3 Bucket without an AWS Account

Introduction

Accessing Amazon S3 (Simple Storage Service) buckets programmatically is a common requirement for many applications. However, setting up and managing AWS accounts is daunting and expensive, especially for small-scale projects or local development environments. In this article, we'll explore how to overcome this hurdle by using Localstack to simulate AWS services. Localstack mimics most AWS services, meaning one can develop and test applications without incurring any costs or relying on an internet connection, which can be incredibly useful for rapid development and debugging. We used ObjectScript with embedded Python to communicate with Intersystems IRIS and AWS simultaneously. Before beginning, ensure you have Python and Docker installed on your system. When Localstack is set up and running, the bucket can be created and used. 

Creating an S3 Bucket from ObjectScript with Embedded Python

Now that LocalStack is running, let's create an S3 bucket programmatically. We'll use Python and the Boto3 library - a Python SDK for AWS services. Take a look at the MakeBucket method provided in the S3UUtil class. This method utilizes Boto3 to create an S3 bucket:

ClassMethod MakeBucket(inboundfromiris As %String) As %Status [ Language = python ]

{

    import boto3

    s3 = boto3.client(

        service_name='s3', 

        region_name="us-east-1", 

        endpoint_url='http://host.docker.internal:4566', 
    )

    try:

        s3.create_bucket(Bucket=inboundfromiris)

        print("Bucket created successfully")

        return 1
    except Exception as e:

        print("Error:", e)

        return 0
}

To create a bucket, you would call this method with the desired bucket name:

status = S3UUtil.MakeBucket("mybucket")

Uploading Objects to the Bucket from ObjectScript with Embedded Python

Once the bucket is created, you can upload objects to it programmatically. The PutObject method demonstrates how to achieve this:

ClassMethod PutObject(inboundfromiris As %String, objectKey As %String) As %Status [ Language = python ]

{

    import boto3

    try:

        content = "Hello, World!".encode('utf-8')

        s3 = boto3.client(

            service_name='s3',

            region_name="us-east-1",

            endpoint_url='http://host.docker.internal:4566'
        )

        s3.put_object(Bucket=inboundfromiris, Key=objectKey, Body=content)

        print("Object uploaded successfully!")

        return 1
    except Exception as e:

        print("Error:", e)

        return 0
}

Call this method to upload an object:

Do ##class(S3.S3UUtil).PutObject("inboundfromiris", "hello-world-test")

 

Listing Objects in the Bucket from ObjectScript with Embedded Python

To list objects in the bucket, you can use the FetchBucket method:

ClassMethod FetchBucket(inboundfromiris As %String) As %Status [ Language = python ]

{

    import boto3

    s3 = boto3.client(

        service_name='s3', 

        region_name="us-east-1", 

        endpoint_url='http://host.docker.internal:4566', 
    )

    try:

        response = s3.list_objects(Bucket=inboundfromiris)

        if 'Contents' in response:

            print("Objects in bucket", inboundfromiris)

            for obj in response['Contents']:

                print(obj['Key'])

            return 1
        else:

            print("Error: Bucket is empty or does not exist")

            return 0
    except Exception as e:

        print("Error:", e)

        return 0
}

Call the FetchBucket method to list objects from the bucket:

do ##class(S3.S3UUtil).FetchBucket("inboundfromiris")


 

Retrieving Objects from the Bucket from ObjectScript with Embedded Python

Finally, to retrieve objects from the bucket, you can use the PullObjectFromBucket method:

ClassMethod PullObjectFromBucket(inboundfromiris As %String, objectKey As %String) As %Status [ Language = python ]

{

    import boto3

    def pull_object_from_bucket(bucket_name, object_key):

        try:

            s3 = boto3.client(

                service_name='s3', 

                region_name="us-east-1", 

                endpoint_url='http://host.docker.internal:4566', 
            )

            obj_response = s3.get_object(Bucket=bucket_name, Key=object_key)

            content = obj_response['Body'].read().decode('utf-8')

            print("Content of object with key '", object_key, "':", content)

            return True

        except Exception as e:

            print("Error:", e)

            return False

    pull_object_from_bucket(inboundfromiris, objectKey)

}

Call this method:

Do ##class(DQS.CloudUtils.S3.S3UUtil).PullObjectFromBucket("inboundfromiris", "hello-world-test")

 

The discussion here is just the beginning, as it's clear there's plenty more ground to cover. I invite readers to dive deeper into this subject and share their insights. Let's keep the conversation going and continue advancing our understanding of this topic.

I'm eager to hear thoughts and contributions.

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
お知らせ
· 2024年5月3日

VS Code release April 2024 (version 1.89)

 

Visual Studio Code releases new updates every month with new features and bug fixes, and the April 2024 release is now available. 

Version 1.89 includes:

The release also includes contributions from our very own @John Murray through pull requests that address open issues. 

Find out more about these features in the release notes here > https://code.visualstudio.com/updates/v1_89

For those with VS Code, your environment should auto-update. You can manually check for updates by running Help > Check for Updates on Linux and Windows or running Code > Check for Updates on macOS.

If you're thinking about migrating from Studio to VS Code but need some help, take a look at the training courses George James Software offers > https://georgejames.com/migration-from-studio/

ディスカッション (0)2
続けるにはログインするか新規登録を行ってください
質問
· 2024年5月3日

What's the most recent non-preview Community Edition Container?

It's not clear to me, when using the InterSystems Container Repository, which version is the best / most recent non-preview Community Edition version to use.

I see lots of 2023.2.x versions, a single 2023.3 and 2024.1 version, but also a latest-cd and latest-em (with no explanation as to what cd and em mean).

I assume the trick is to use one of the latest-xx ones?  If so, which?

Unfortunately I haven't been able to find any explanatory information anywhere about the nomenclature conventions used.

Many thanks

5 Comments
ディスカッション (5)3
続けるにはログインするか新規登録を行ってください
お知らせ
· 2024年5月3日

Ya está aquí el resumen del mes de abril, 2024

¿No habéis podido entrar en la Comunidad todo lo que os gustaría? ¡No os preocupéis! Os traemos un resumen de todo lo que hemos publicado en el mes. Seguid leyendo y no os lo perdáis ⬇️⬇️
Estadísticas generales
✓ publicaciones nuevas:
 10 artículos
 10 anuncios
 2 nuevas preguntas
Top 10 Publicaciones más vistas
Introducción a Kubernetes
Por Luis Angel Pérez Ramos
Top 5 Autores más populares
Todos los artículos
#InterSystems IRIS
QuinielaML - Predicciones de la 49ª jornada de la Quiniela
Por Luis Angel Pérez Ramos
Conectar Microsoft Excel a InterSystems IRIS mediante ODBC (Windows)
Por Alberto Fuentes
QuinielaML - Predicciones de la 51ª jornada de la Quiniela
Por Luis Angel Pérez Ramos
QuinielaML - Predicciones de la 53ª jornada de la Quiniela
Por Luis Angel Pérez Ramos
Cómo instalar soluciones ObjectScript sin código fuente o en modo de despliegue mediante el gestor de paquetes IPM
Por Alberto Fuentes
QuinielaML - Predicciones de la 54ª jornada de la Quiniela
Por Luis Angel Pérez Ramos
Comprobación de Versión en objetos. "ERROR:5800"
Por Ricardo Paiva
Rastreos de OpenTelemetry implementados por Servicios Web SOAP en IRIS
Por Jose-Tomas Salvador
Flujos de tareas con InterSystems IRIS Workflow Engine - Introducción
Por Luis Angel Pérez Ramos
 
#Otro
Introducción a Kubernetes
Por Luis Angel Pérez Ramos
 
Todos los anuncios
#InterSystems IRIS
 
#Comunidad de Desarrolladores Oficial
 
#Otro
 
#InterSystems Official
 
#HealthShare
 
#Global Masters
 
Todas las preguntas
abril, 2024Month at a GlanceInterSystems Developer Community
ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2024年5月2日 3m read

LinuxでODBC接続を行う方法

こちらの記事では、LinuxでODBC接続の設定を行う方法をご紹介します。


はじめに、Linuxのバージョンを確認します。

$ cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="9.4 (Plow)"
:


1. yumパッケージのアップデートを行います

$ sudo yum update


2. unixODBCをインストールします

$ sudo yum install unixODBC

確認します

$ which odbcinst
/usr/bin/odbcinst
$ which isql
/usr/bin/isql
$ odbcinst -j
unixODBC 2.3.9
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/ec2-user/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8


3. IRISクライアントをインストールします

※Linuxのバージョンにあったインストーラを使用してください。

$ cd IRIS-2024.1.0.262.0-lnxrh9x64

$ sudo ./irisinstall_client
Your system type is 'Red Hat Enterprise Linux 9 (x64)'.
Enter a destination directory for client components.
Directory: /intersystems/iris
Directory '/intersystems/iris' does not exist.
Do you want to create it <Yes>?
Installation completed successfully


4. 構成ファイルの作成をします

※SYSTEM DATA SOURCES: /etc/odbc.ini に以下を追加します

[ODBC Data Sources]
InterSystemsODBC6435 = InterSystemsODBC6435

[InterSystemsODBC6435]
Description=InterSystems ODBC
Driver = /intersystems/iris/bin/libirisodbcur6435.so
Setup = /intersystems/iris/bin/libirisodbcur6435.so
Unicode SQLTypes = 1
Host=***.***.***.***
Namespace=USER
UID=_SYSTEM
Password=SYS
Port=1972
$ sudo vi /etc/odbc.ini 


5. 環境変数:ODBCINIの登録をします 

※すべてのユーザで使用できるよう、環境変数を永続化させます。

$ sudo vi /etc/profile

# ---- 以下を追加
export ODBCINI=/etc/odbc.ini

(設定を反映させるために、一度ログアウトして再度ログインします)

$ echo $ODBCINI
/etc/odbc.ini

※ご参考:初期化ファイルの名前と場所


6. IRISへのODBC接続確認をします

$ isql -v InterSystemsODBC6435
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> SELECT count(*) FROM INFORMATION_SCHEMA.TABLES
+---------------------+
| Aggregate_1         |
+---------------------+
| 429                 |
+---------------------+
SQLRowCount returns 1
1 rows fetched
SQL>

 

今回は、IRISクライアントインストールで試しましたが、ODBCドライバ単体のインストールも可能です。
詳細は以下のドキュメントをご覧ください。
UNIX® システムでの ODBC のインストールと検証


ODBCデータソースの定義についての詳細は、以下のドキュメントをご覧ください。
UNIX® での ODBC データ・ソースの定義
 

enlightened【ご参考】
PyODBC経由でIRISに接続するAWS Lambda関数を作成するまでの流れ
LinuxでJDBC接続を行う方法

ディスカッション (0)0
続けるにはログインするか新規登録を行ってください