Java SDK を使用して Simple Message Queue (SMQ) リクエストを送信するには、エンドポイントとアクセス資格情報を設定する必要があります。Alibaba Cloud サービスは、アクセス資格情報を使用してアイデンティティとアクセス権限を検証します。ユースケースの認証と認可の要件に応じて、異なるタイプのアクセス資格情報を選択できます。このトピックでは、エンドポイント、一時的なアクセス資格情報、長期的なアクセス資格情報を設定する方法について説明します。
エンドポイントの設定
aliyun-mns.properties ファイルに ApsaraMQ のパブリックエンドポイントまたは内部エンドポイントを設定します。このファイルは通常、${user.home}/.aliyun-mns.properties にあります。
Linux および macOS では、aliyun-mns.properties ファイルは ~/.aliyun-mns.properties にあります。
Windows では、aliyun-mns.properties ファイルは %USERPROFILE%\.aliyun-mns.properties にあります。
aliyun-mns.properties ファイルを次のように設定します。
mns.accountendpoint=http://120228xxxxxxx.mns.cn-xxxxxx.aliyuncs.com
ApsaraMQ のエンドポイントは、コンソールの キューの詳細 または トピックの詳細 ページにある[エンドポイント]セクションで確認できます。
アクセスクレデンシャル
以下の種類のアクセス認証情報を使用できます。
-
長期アクセス認証情報: セキュリティを最大限に高めるには、長期アクセス認証情報ではなく一時的アクセス認証情報を使用してください。長期アクセス認証情報は、頻繁に更新する必要がないため便利です。アカウントのセキュリティを強化するために、長期アクセス認証情報は 3 か月ごとにローテーションしてください。長期アクセス認証情報が侵害された場合、または使用されなくなった場合は、セキュリティリスク を防ぐために直ちに削除または無効化してください。
-
一時的アクセス認証情報: アプリケーションに SMQ へのアクセスを一時的に認可する場合など、高度なセキュリティが求められるユースケースでは、一時的アクセス認証情報を使用してください。これらの認証情報は限られた期間のみ有効であるため、認証情報の侵害のリスクが軽減されます。さらに、これらはきめ細かなアクセス制御をサポートしているため、過剰な権限によるセキュリティリスク の回避に役立ちます。
長期アクセス認証情報
アプリケーションまたはサービスで SDK for Java を使用して ApsaraMQ へ長期的にアクセスする準備ができたら、次のいずれかの方法で長期アクセス認証情報を設定します。
RAM ユーザーの AccessKey ペアの構成:SMQ に長期的にアクセスする必要がある場合は、RAM ユーザーの AccessKey ペア を使用して SMQ にアクセスできます。
-
RAM ユーザーのアクセスキーペアを取得します。
RAM ユーザーのアクセスキーペアを取得する方法については、「RAM ユーザーのアクセスキーペアの作成」をご参照ください。
重要セキュリティのベストプラクティスとして、アクセスキーペアを 3 か月以上使用している場合はローテーションしてください。アクセスキーペアを長期間使用しない場合は、漏洩のリスクを軽減するために無効化または削除してください。
-
RAM ユーザーのアクセスキーペアを設定します。
環境変数
-
環境変数を設定します。
macOS
-
ターミナルを開きます。
-
次のコマンドを実行します。
nano ~/.bash_profile -
ファイルの末尾に次の行を追加します。
export ALIBABA_CLOUD_ACCESS_KEY_ID=LTA**** export ALIBABA_CLOUD_ACCESS_KEY_SECRET=moiEs**** -
Ctrl+Xキーを押し、Yキーを押して確認してから、Enterキーを押して保存して終了します。 -
次のコマンドを実行して変更を適用します。
source ~/.bash_profile -
次のコマンドを実行して設定を確認します。
echo $ALIBABA_CLOUD_ACCESS_KEY_ID echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET次の出力は、設定が成功したことを示します。
LTA**** moiEs****
Linux
-
ターミナルを開きます。
-
次のコマンドを実行します。
sudo vim /etc/profile -
ファイルの末尾に次の行を追加します。
export ALIBABA_CLOUD_ACCESS_KEY_ID=LTA**** export ALIBABA_CLOUD_ACCESS_KEY_SECRET=moiEs**** -
Escキーを押して編集モードを終了し、:wqと入力してからEnterキーを押して保存して終了します。 -
次のコマンドを実行して変更を適用します。
source /etc/profile -
次のコマンドを実行して設定を確認します。
echo $ALIBABA_CLOUD_ACCESS_KEY_ID echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET次の出力は、設定が成功したことを示します。
LTA**** moiEs****
Windows
GUI
次の手順は、Windows 10 の GUI を使用してアクセスキーペアを環境変数として設定する方法を示します。
-
デスクトップで [This PC] を右クリックし、[Properties] を選択します。[Advanced system settings] > [Environment Variables] に移動します。[System variables] または [User variables] セクションで [New] をクリックします。
-
次の環境変数を追加します。
パラメーター
値
ALIBABA_CLOUD_ACCESS_KEY_ID
LTA****
ALIBABA_CLOUD_ACCESS_KEY_SECRET
moiEs****
-
設定を確認するには、新しいコマンド プロンプトウィンドウを開き、次のコマンドを実行します。
echo %ALIBABA_CLOUD_ACCESS_KEY_ID% echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%次の出力は、設定が成功したことを示します。
LTA**** moiEs****
コマンド プロンプト (CMD)
-
コマンド プロンプトを開きます。
-
次のコマンドを実行して、RAM ユーザーのアクセスキーペアを設定します。
set ALIBABA_CLOUD_ACCESS_KEY_ID=LTA**** set ALIBABA_CLOUD_ACCESS_KEY_SECRET=moiEs**** -
これらの変数をセッション間で永続化するには、次のコマンドを実行します。
setx ALIBABA_CLOUD_ACCESS_KEY_ID "%ALIBABA_CLOUD_ACCESS_KEY_ID%" setx ALIBABA_CLOUD_ACCESS_KEY_SECRET "%ALIBABA_CLOUD_ACCESS_KEY_SECRET%" -
次のコマンドを実行して、環境変数が設定されていることを確認します。
echo %ALIBABA_CLOUD_ACCESS_KEY_ID% echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%次の出力は、設定が成功したことを示します。
LTA**** moiEs****
Windows PowerShell
-
Win+Xキーを押します。 -
次のいずれかの方法を選択してアクセスキーペアを設定します。
現在のセッション
-
表示されるメニューから [Windows PowerShell] を選択します。
-
現在のセッション用に次の環境変数を追加します。
$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "LTA****" $env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "moiEs****"
新しいセッション
-
表示されるメニューから [Windows PowerShell] を選択します。
-
すべての新しいセッション用に次の環境変数を追加します。
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'LTA****', [System.EnvironmentVariableTarget]::User) [System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'moiEs****', [System.EnvironmentVariableTarget]::User)
すべてのユーザー
-
表示されるメニューから [Windows PowerShell (Administrator)] を選択します。
-
すべてのユーザー用に次の環境変数を追加します。
[System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_ID', 'LTA****', [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'moiEs****', [System.EnvironmentVariableTarget]::Machine)
-
-
設定を確認するには、新しい PowerShell ウィンドウで次のコマンドを実行します。
echo $env:ALIBABA_CLOUD_ACCESS_KEY_ID echo $env:ALIBABA_CLOUD_ACCESS_KEY_SECRET次の出力は、設定が成功したことを示します。
LTA**** moiEs****
-
-
アプリケーションは、環境変数からアクセスキーペアを取得できます。次の Java コードは、これらの変数を暗黙的に使用するクライアントを作成する例を示します。
// SDK クライアントは、明示的な認証情報が指定されていない場合、 // 認証のために環境変数を暗黙的に使用します。 CloudAccount account = new CloudAccount(ServiceSettings.getMNSAccountEndpoint());
コードへの埋め込み
警告アクセス認証情報をコードに埋め込むと、セキュリティリスクが生じます。アクセス認証情報が漏洩した場合、攻撃者はそれを使用して MNS リソースにアクセスできます。セキュリティを強化するため、環境変数からアクセス認証情報を取得するなど、より安全な方法を使用することを推奨します。
CloudAccount account = new CloudAccount("LTA****", "moiEs****", ServiceSettings.getMNSAccountEndpoint()); -
一時的なアクセス認証情報
Java SDK を使用して ApsaraMQ for Kafka に一時的にアクセスするには、次のいずれかの方法で一時的なアクセス認証情報を設定します:
-
STS の一時的なアクセス認証情報の構成:SMQ に一定期間アクセスするには、STS を使用して一時的なアクセス認証情報を発行します。この認証情報を使用すると、RAM ユーザーの AccessKey ペアを公開することなく、SMQ に安全にアクセスできます。
-
RAM ロールの構成:アカウント内またはアカウント間で SMQ へのアクセスを付与するには、RAM ロールを使用します。その後、RAM ユーザーがロールを引き受けて SMQ にアクセスできます。
-
ECS インスタンスの RAM ロールを設定する: Alibaba Cloud ECS インスタンスから SMQ にアクセスする必要がある場合は、ECS インスタンス RAM ロールを使用して SMQ にアクセスできます。インスタンス RAM ロールを使用すると、ロールを ECS インスタンスに関連付け、STS 一時認証情報を使用してインスタンス内から SMQ にアクセスできます。STS 一時認証情報はシステムによって自動的に生成および更新され、アプリケーションは手動で管理することなく、指定されたインスタンスメタデータ URL を使用して一時認証情報を取得できます。
STS temporary access credentials
-
Create a RAM user.
For more information, see Create a RAM user.
-
Attach the
AliyunSTSAssumeRoleAccesspolicy to the RAM user.For more information, see Manage RAM user permissions.
-
Use the RAM user to call the AssumeRole operation of STS to obtain STS temporary access credentials.
For more information, see AssumeRole.
-
Configure the STS temporary access credentials.
Environment variables
-
Set the environment variables using the obtained STS temporary access credentials.
macOS
-
Open the terminal.
-
Run the following command:
nano ~/.bash_profile -
Add the temporary access credentials (AccessKey ID, AccessKey Secret, and security token) to the end of the file.
export MNS_ACCESS_KEY_ID=LTA**** export MNS_ACCESS_KEY_SECRET=moiEs**** export MNS_SESSION_TOKEN=CAES**** -
Press
Ctrl+X, pressYto save the changes, and then pressEnterto exit. -
Run the following command to apply the changes:
source ~/.bash_profile -
Run the following commands to verify the environment variables:
echo $MNS_ACCESS_KEY_ID echo $MNS_ACCESS_KEY_SECRET echo $MNS_SESSION_TOKENThe following is a sample output:
LTA**** moiEs**** CAES****
Linux
-
Open the terminal.
-
Run the following command:
sudo vim /etc/profile -
Add the temporary access credentials (AccessKey ID, AccessKey Secret, and security token) to the end of the file.
export MNS_ACCESS_KEY_ID=LTA**** export MNS_ACCESS_KEY_SECRET=moiEs**** export MNS_SESSION_TOKEN=CAES**** -
Press
ESCto exit the editing mode, enter:wq, and then pressEnterto save and exit the file. -
Run the following command to apply the changes:
source /etc/profile -
Run the following commands to verify the environment variables:
echo $MNS_ACCESS_KEY_ID echo $MNS_ACCESS_KEY_SECRET echo $MNS_SESSION_TOKENThe following is a sample output:
LTA**** moiEs**** CAES****
Windows
GUI
This section shows how to set STS temporary access credentials as environment variables by using the GUI in Windows 10.
-
On your desktop, right-click This PC and select Properties > Advanced system settings > Environment Variables. In the User variables or System variables section, click New.
-
Add the following environment variables:
Parameter
Value
MNS_ACCESS_KEY_ID
LTA****
MNS_ACCESS_KEY_SECRET
moiEs****
MNS_SESSION_TOKEN
CAES****
-
Run the following commands to verify the environment variables:
echo %MNS_ACCESS_KEY_ID% echo %MNS_ACCESS_KEY_SECRET% echo %MNS_SESSION_TOKEN%The following is a sample output:
LTA**** moiEs**** CAES****
Command Prompt
-
Open Command Prompt.
-
Run the following commands to set the temporary access credentials (AccessKey ID, AccessKey Secret, and security token).
set MNS_ACCESS_KEY_ID=LTA**** set MNS_ACCESS_KEY_SECRET=moiEs**** set MNS_SESSION_TOKEN=CAES**** -
Run the following commands to apply the changes:
setx MNS_ACCESS_KEY_ID "%MNS_ACCESS_KEY_ID%" setx MNS_ACCESS_KEY_SECRET "%MNS_ACCESS_KEY_SECRET%" setx MNS_SESSION_TOKEN "%MNS_SESSION_TOKEN%" -
Run the following commands to verify the environment variables:
echo %MNS_ACCESS_KEY_ID% echo %MNS_ACCESS_KEY_SECRET% echo %MNS_SESSION_TOKEN%The following is a sample output:
LTA**** moiEs**** CAES****
Windows PowerShell
-
Press
Win + X. -
Set the STS temporary access credentials.
Current session
-
From the menu that appears, select Windows PowerShell.
-
Set the following environment variables for the current session:
$env:MNS_ACCESS_KEY_ID = "LTA****" $env:MNS_ACCESS_KEY_SECRET = "moiEs****" $env:MNS_SESSION_TOKEN = "CAE****"
New sessions
-
From the menu that appears, select Windows PowerShell.
-
Set the following environment variables for all new sessions:
[System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_ID', 'LTA****', [System.EnvironmentVariableTarget]::User) [System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_SECRET', 'moiEs****', [System.EnvironmentVariableTarget]::User) [System.Environment]::SetEnvironmentVariable('MNS_SESSION_TOKEN', 'CAES****', [System.EnvironmentVariableTarget]::User)
All users
-
From the menu that appears, select Windows PowerShell (Administrator).
-
Set the following environment variables for all users:
[System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_ID', 'LTA****', [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_SECRET', 'moiEs****', [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable('MNS_SESSION_TOKEN', 'CAES****', [System.EnvironmentVariableTarget]::Machine)
-
-
Run the following commands to verify the environment variables:
Get-ChildItem env:MNS_ACCESS_KEY_ID Get-ChildItem env:MNS_ACCESS_KEY_SECRET Get-ChildItem env:MNS_SESSION_TOKENThe following is a sample output:
LTA**** moiEs**** CAES****
-
-
Obtain the STS temporary access credentials from the environment variables.
// Obtain the STS temporary access credentials from environment variables. String accessKeyId = System.getenv("MNS_ACCESS_KEY_ID"); String accessKeySecret = System.getenv("MNS_ACCESS_KEY_SECRET"); String sessionToken = System.getenv("MNS_SESSION_TOKEN"); AlibabaCloudCredentials credentials = new BasicSessionCredentials(accessKeyId,accessKeySecret,sessionToken); AlibabaCloudCredentialsProvider provider = new StaticCredentialsProvider(credentials);
Embed in code
警告Embedding access credentials in your code poses a security risk. If leaked, these credentials can be used by attackers to access your MNS resources. For enhanced security, we recommend using a more secure method, such as obtaining access credentials from environment variables.
// WARNING: Hardcoding credentials is a security risk. String accessKeyId = "LTAI************"; // Replace with your AccessKey ID. String accessKeySecret = "K_VTN*******************"; // Replace with your AccessKey Secret. String sessionToken = "CAES********************"; // Replace with your security token. AlibabaCloudCredentials credentials = new BasicSessionCredentials(accessKeyId,accessKeySecret,sessionToken); AlibabaCloudCredentialsProvider provider = new StaticCredentialsProvider(credentials); String endpoint = ServiceSettings.getMNSAccountEndpoint(); CloudAccount account = new CloudAccount(endpoint, provider); -
RAM role
-
Obtain the AccessKey pair of the RAM user.
For more information, see Create an AccessKey pair for a RAM user.
重要To reduce the risk of an AccessKey pair leak, we recommend that you rotate an AccessKey pair if it has been used for more than three months. If an AccessKey pair is no longer needed, disable and delete it promptly.
-
Obtain the RAM Role ARN of the target RAM role.
説明A RAM Role ARN is the Alibaba Cloud Resource Name (ARN) of a RAM role, which identifies the role to assume. It follows the format: acs:ram::$accountID:role/$roleName, where $accountID is the ID of your Alibaba Cloud account and $roleName is the name of the RAM role.
For more information, see View a RAM role.
-
Configure the AccessKey pair of the RAM user and the RAM Role ARN of the target RAM role as the access credentials.
Environment variables
-
Set environment variables using the RAM user's AccessKey pair and the target RAM Role ARN.
macOS
-
Open the terminal.
-
Run the following command:
nano ~/.bash_profile -
Add the RAM user's AccessKey pair and the RAM Role ARN to the end of the file.
export MNS_ACCESS_KEY_ID=LTAI**** export MNS_ACCESS_KEY_SECRET=IrVTNZNy**** export MNS_STS_ROLE_ARN=acs:ram::17464958********:role/mnsststest -
Press
Ctrl+X, pressYto save the changes, and then pressEnterto exit. -
Run the following command to apply the changes:
source ~/.bash_profile -
Run the following commands to verify the environment variables:
echo $MNS_ACCESS_KEY_ID echo $MNS_ACCESS_KEY_SECRET echo $MNS_STS_ROLE_ARNThe following is a sample output:
LTAI**** IrVTNZNy**** acs:ram::17464958********:role/mnsststest
Linux
-
Open the terminal.
-
Run the following command:
sudo vim /etc/profile -
Add the RAM user's AccessKey pair and the RAM Role ARN to the end of the file.
export MNS_ACCESS_KEY_ID=LTAI**** export MNS_ACCESS_KEY_SECRET=IrVTNZNy**** export MNS_STS_ROLE_ARN=acs:ram::17464958********:role/mnsststest -
Press
ESCto exit the editing mode, enter:wq, and then pressEnterto save and exit the file. -
Run the following command to apply the changes:
source /etc/profile -
Run the following commands to verify the environment variables:
echo $MNS_ACCESS_KEY_ID echo $MNS_ACCESS_KEY_SECRET echo $MNS_STS_ROLE_ARNThe following is a sample output:
LTAI**** IrVTNZNy**** acs:ram::17464958********:role/mnsststest
Windows
GUI
This section shows how to use the GUI in Windows 10 to set environment variables for the RAM user's AccessKey pair and the target RAM Role ARN.
-
On your desktop, right-click This PC and select Properties > Advanced system settings > Environment Variables. In the User variables or System variables section, click New.
-
Add the following environment variables:
Parameter
Value
MNS_ACCESS_KEY_ID
LTAI****
MNS_ACCESS_KEY_SECRET
IrVTNZNy****
MNS_STS_ROLE_ARN
acs:ram::17464958********:role/mnsststest
-
Run the following commands to verify the environment variables:
echo %MNS_ACCESS_KEY_ID% echo %MNS_ACCESS_KEY_SECRET% echo %MNS_STS_ROLE_ARN%The following is a sample output:
LTAI**** IrVTNZNy**** acs:ram::17464958********:role/mnsststest
Command Prompt
-
Open Command Prompt.
-
Run the following commands to set the AccessKey pair of the RAM user and the RAM Role ARN:
set MNS_ACCESS_KEY_ID=LTAI**** set MNS_ACCESS_KEY_SECRET=IrVTNZNy**** set MNS_STS_ROLE_ARN=acs:ram::17464958********:role/mnsststest -
Run the following commands to apply the changes:
setx MNS_ACCESS_KEY_ID "%MNS_ACCESS_KEY_ID%" setx MNS_ACCESS_KEY_SECRET "%MNS_ACCESS_KEY_SECRET%" setx MNS_STS_ROLE_ARN "%MNS_STS_ROLE_ARN%" -
Run the following commands to verify the environment variables:
echo %MNS_ACCESS_KEY_ID% echo %MNS_ACCESS_KEY_SECRET% echo %MNS_STS_ROLE_ARN%The following is a sample output:
LTAI**** IrVTNZNy**** acs:ram::17464958********:role/mnsststest
Windows PowerShell
-
Press
Win + X. -
Set the AccessKey pair of the RAM user and the RAM Role ARN of the target RAM role.
Current session
-
From the menu that appears, select Windows PowerShell.
-
Set the following environment variables for the current session:
$env:MNS_ACCESS_KEY_ID = "LTAI****" $env:MNS_ACCESS_KEY_SECRET = "IrVTNZNy****" $env:MNS_STS_ROLE_ARN = "acs:ram::17464958********:role/mnsststest"
New sessions
-
From the menu that appears, select Windows PowerShell.
-
Set the following environment variables for all new sessions:
[System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_ID', 'LTAI****', [System.EnvironmentVariableTarget]::User) [System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_SECRET', 'IrVTNZNy****', [System.EnvironmentVariableTarget]::User) [System.Environment]::SetEnvironmentVariable('MNS_STS_ROLE_ARN', 'acs:ram::17464958********:role/mnsststest', [System.EnvironmentVariableTarget]::User)
All users
-
From the menu that appears, select Windows PowerShell (Administrator).
-
Set the following environment variables for all users:
[System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_ID', 'LTAI****', [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable('MNS_ACCESS_KEY_SECRET', 'IrVTNZNy****', [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable('MNS_STS_ROLE_ARN', 'acs:ram::17464958********:role/mnsststest', [System.EnvironmentVariableTarget]::Machine)
-
-
Run the following commands to verify the environment variables:
Get-ChildItem env:MNS_ACCESS_KEY_ID Get-ChildItem env:MNS_ACCESS_KEY_SECRET Get-ChildItem env:MNS_STS_ROLE_ARNThe following is a sample output:
LTAI**** IrVTNZNy**** acs:ram::17464958********:role/mnsststest
-
-
Obtain the AccessKey pair of the RAM user and the RAM Role ARN from the environment variables.
// The region where STSAssumeRole is authorized. This example uses China (Hangzhou). String region = "cn-hangzhou"; // Obtain the AccessKey pair (AccessKey ID and AccessKey Secret) of the RAM user from the environment variables. String accessKeyId = System.getenv("MNS_ACCESS_KEY_ID"); String accessKeySecret = System.getenv("MNS_ACCESS_KEY_SECRET"); // Obtain the RAM Role ARN from the environment variable. String roleArn = System.getenv("MNS_STS_ROLE_ARN"); // Configure the access credentials by using the AccessKey pair of the RAM user and the RAM Role ARN obtained from the environment variables. STSAssumeRoleSessionCredentialsProvider credentialsProvider = CredentialsProviderFactory .newSTSAssumeRoleSessionCredentialsProvider( region, accessKeyId, accessKeySecret, roleArn );
Embed in code
警告Embedding access credentials in your code poses a security risk. If leaked, these credentials can be used by attackers to access your MNS resources. For enhanced security, we recommend using a more secure method, such as obtaining access credentials from environment variables.
// WARNING: Hardcoding credentials is a security risk. // The region ID must match the MNS endpoint. String regionId = "cn-hangzhou"; // Replace the following with your RAM user's AccessKey pair and the target RAM Role ARN. String accessKeyId = "LTAI************"; // The AccessKey ID of the RAM user. String accessKeySecret = "K_VTN*******************"; // The AccessKey Secret of the RAM user. String roleArn = "acs:ram::17464958********:role/mnsststest"; // The ARN of the RAM role to assume. DefaultProfile profile = DefaultProfile.getProfile(regionId); AlibabaCloudCredentialsProvider provider = new STSAssumeRoleSessionCredentialsProvider( new BasicCredentials(accessKeyId, accessKeySecret), roleArn, profile ); String endpoint = ServiceSettings.getMNSAccountEndpoint(); CloudAccount account = new CloudAccount(endpoint, provider); -
ECS RAM role
-
Assign a RAM role to an ECS instance.
For more information, see Attach an instance RAM role.
-
Configure the ECS instance RAM role as the access credentials.
// Obtain access credentials from the 'ecs-ram-role' ECS instance RAM role. CredentialsProvider provider = new InstanceProfileCredentialsProvider("ecs-ram-role");