Wir testen Amazon's AWS SDK mit dem folgenden Beispielprogramm. Siehe den Quellcode im Abschnitt Details. Über den Profilnamen siehe Chain.trygetawscredentials (Profil, out awScredentials) . Und dieser logische Pfad funktioniert in Ordnung, und wir erhalten die Ergebnismeldung von "Erfolg". Die Anmeldeinformationen.
awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
ssmClient = new AmazonSimpleSystemsManagementClient(awsCredentials);
< /code>
und das Programm trifft schließlich auf die folgende Ausnahme: < /p>
Fehler: Benutzer: ARN: AWS: IAM :: XXX : user/xxx-xxx-xxx ist nicht autorisiert, um auszuführen: SSM: sendCommand on ressource: ARN: AWS: EC2: Region_endpoint: xxxxxx: Instanz/i-xxxxxx, da keine identitätsbasierte Richtlinie die SSM: sendCommand-Aktion
< /blockquote>
Da der erste logische Pfad erfolgreich funktioniert, beweist es, dass unser Anmeldeinformator alle erforderlichen Vorräte zur Durchführung der Testaktion hat. Wir vermuten also, dass der zweite logische Pfad etwas verpasst hat, um den AWS -Anmeldeinformationen zu erhalten. Details:
[b] Quellcode der Testfunktion: [/b]
public static async Task ConnectByAWSRunShellScript(
string instanceId,
string databaseHost,
string databaseUsername,
string databasePassword,
string databaseName,
RegionEndpoint regionEndpoint,
string accessKey,
string secretKey)
{
try
{
AWSCredentials awsCredentials;
AmazonSimpleSystemsManagementClient ssmClient;
bool isUseProfile = true;
if (isUseProfile == true)
{
var profile = "profile_name";
var chain = new CredentialProfileStoreChain();
if (!chain.TryGetAWSCredentials(profile, out awsCredentials))
{
Console.WriteLine("Failed to get AWS credentials");
return;
}
ssmClient = new AmazonSimpleSystemsManagementClient(awsCredentials);
}
else
{
awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
ssmClient = new AmazonSimpleSystemsManagementClient(awsCredentials);
}
var command = $"hostname";
var sendCommandRequest = new SendCommandRequest
{
InstanceIds = new List { instanceId },
DocumentName = "AWS-RunShellScript",
Parameters = new Dictionary
{
{ "commands", new List { command } }
}
};
var sendCommandResponse = await ssmClient.SendCommandAsync(sendCommandRequest);
if (sendCommandResponse != null)
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("Fail");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
Wir testen Amazon's AWS SDK mit dem folgenden Beispielprogramm. Siehe den Quellcode im Abschnitt Details. Über den Profilnamen siehe Chain.trygetawscredentials (Profil, out awScredentials) . Und dieser logische Pfad funktioniert in Ordnung, und wir erhalten die Ergebnismeldung von "Erfolg". Die Anmeldeinformationen.[code]awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ssmClient = new AmazonSimpleSystemsManagementClient(awsCredentials); < /code> und das Programm trifft schließlich auf die folgende Ausnahme: < /p>
Fehler: Benutzer: ARN: AWS: IAM :: XXX : user/xxx-xxx-xxx ist nicht autorisiert, um auszuführen: SSM: sendCommand on ressource: ARN: AWS: EC2: Region_endpoint: xxxxxx: Instanz/i-xxxxxx, da keine identitätsbasierte Richtlinie die SSM: sendCommand-Aktion < /blockquote> Da der erste logische Pfad erfolgreich funktioniert, beweist es, dass unser Anmeldeinformator alle erforderlichen Vorräte zur Durchführung der Testaktion hat. Wir vermuten also, dass der zweite logische Pfad etwas verpasst hat, um den AWS -Anmeldeinformationen zu erhalten. Details: [b] Quellcode der Testfunktion: [/b] public static async Task ConnectByAWSRunShellScript( string instanceId, string databaseHost, string databaseUsername, string databasePassword, string databaseName, RegionEndpoint regionEndpoint, string accessKey, string secretKey) { try { AWSCredentials awsCredentials; AmazonSimpleSystemsManagementClient ssmClient;
bool isUseProfile = true; if (isUseProfile == true) { var profile = "profile_name"; var chain = new CredentialProfileStoreChain(); if (!chain.TryGetAWSCredentials(profile, out awsCredentials)) { Console.WriteLine("Failed to get AWS credentials"); return; } ssmClient = new AmazonSimpleSystemsManagementClient(awsCredentials); } else { awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ssmClient = new AmazonSimpleSystemsManagementClient(awsCredentials); }
var command = $"hostname"; var sendCommandRequest = new SendCommandRequest { InstanceIds = new List { instanceId }, DocumentName = "AWS-RunShellScript", Parameters = new Dictionary { { "commands", new List { command } } } };
Ich möchte die
Umgebungsvariablen AWS_ACCESS_KEY_ID, AWS_SECRET_KEY oder AWS_SECRET_ACCESS_KEY und AWS_SESSION_TOKEN festlegen
BasicSessionCredentials awsCreds = new BasicSessionCredentials(...
Ich habe meinen Schlüsselgewölbe mit einem Schlüssel namens Azure-Clientsecret konfiguriert, der vom Schlüsselverluderkonfigurationsanbieter abgerufen und den Schlüsselnamen Azure: Clientcret von...
Ich habe eine auf Google Cloud Run gehostete .NET-Anwendung, die auf den GCP Secret Manager zugreifen muss. Meine Anwendung funktioniert ohne Proxy einwandfrei, aber wenn ich mithilfe von...