Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
为存储在 Secrets Manager 中的密钥创建配置文件
以下每个示例都包含有关代码所执行操作的注释。本节中的示例调用以下 API:
- Java
-
private void createSecretsManagerConfigProfile() {
AppConfigClient appconfig = AppConfigClient.create();
// Create an application
CreateApplicationResponse app = appconfig.createApplication(req -> req.name("MyDemoApp"));
// Create a configuration profile for Secrets Manager Secret
CreateConfigurationProfileResponse configProfile = appconfig.createConfigurationProfile(req -> req
.applicationId(app.id())
.name("MyConfigProfile")
.locationUri("secretsmanager://MySecret")
.retrievalRoleArn("arn:aws:iam::000000000000:role/RoleTrustedByAppConfigThatCanRetrieveSecret")
.type("AWS.Freeform"));
}
- Python
-
import boto3
appconfig = boto3.client('appconfig')
# create an application
application = appconfig.create_application(Name='MyDemoApp')
# create a configuration profile for Secrets Manager Secret
config_profile = appconfig.create_configuration_profile(
ApplicationId=application['Id'],
Name='MyConfigProfile',
LocationUri='secretsmanager://MySecret',
RetrievalRoleArn='arn:aws:iam::000000000000:role/RoleTrustedByAppConfigThatCanRetrieveSecret',
Type='AWS.Freeform')
- JavaScript
-
import {
AppConfigClient,
CreateConfigurationProfileCommand,
} from "@aws-sdk/client-appconfig";
const appconfig = new AppConfigClient();
// create an application
const application = await appconfig.send(
new CreateApplicationCommand({ Name: "MyDemoApp" })
);
// create a configuration profile for Secrets Manager Secret
await appconfig.send(
new CreateConfigurationProfileCommand({
ApplicationId: application.Id,
Name: "MyConfigProfile",
LocationUri: "secretsmanager://MySecret",
RetrievalRoleArn: "arn:aws:iam::000000000000:role/RoleTrustedByAppConfigThatCanRetrieveSecret",
Type: "AWS.Freeform",
})
);