我想知道这是否可能--我需要从AWS存储中获取参数,以便在每个环境中使用某些值,而无需每次重新部署角应用程序来获取appSettings.json中的更改
下面的代码在SessionToken到期之前运行良好。这是一个公共网站,所以不会有一个创作的用户。
import { Injectable } from '@angular/core';
import { SSMClient, GetParameterCommand, GetParameterCommandInput } from '@aws-sdk/client-ssm';
import { fromTemporaryCredentials } from '@aws-sdk/credential-providers';
@Injectable({
providedIn: 'root'
})
export class SsmService {
constructor() {}
creds = {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
sessionToken: 'sessionToken'
}
tempCreds = fromTemporaryCredentials({
masterCredentials: this.creds,
params: {
RoleArn: 'arn:RoleArn',
RoleSessionName: 'RoleSessionName',
DurationSeconds: 3600
},
clientConfig: {
region: 'eu-west-2'
}
});
client: SSMClient = new SSMSClient(
{
region: 'eu-west-2',
credentials: this.tempCreds
});
async getParameterValue(name: string): Promise<string> {
const input: GetParameterCommandInput = {
Name: name
}
const command = new GetParameterCommand(input);
return await this.client.send(command).Parameter?.Value ?? '';
}
}在没有SessionToken的情况下可以获得参数吗?
发布于 2021-12-28 08:01:48
不是的。如果没有有效的会话令牌,就无法调用API。
我有下面的代码,它在SessionToken过期之前运行良好。
为什么不在旧令牌过期之前从STS获得一个新的会话令牌?
在没有凭据和身份验证的情况下获取配置数据的一种方法是从本地配置文件加载配置数据(例如,请参阅https://jooooel.com/angular-config-from-an-external-source/)。当然,这不能用于加载凭据或其他机密数据。其想法是将非机密配置和设置数据存储在json文件中,并在应用程序启动前动态加载数据。每个环境都可以有不同的配置文件。
https://stackoverflow.com/questions/70450492
复制相似问题