【发布时间】:2022-01-23 18:18:37
【问题描述】:
我想知道这是否可能 - 我需要从 AWS 商店获取参数以在每个环境中使用某些值,而无需每次都重新部署 Angular 应用程序来获取 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 {
const input: GetParameterCommandInput = {
Name: name
}
const command = new GetParameterCommand(input);
return await this.client.send(command).Parameter?.Value ?? '';
}
}
没有SessionToken可以获取参数吗?