

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 第 2 步：创建 AWS Service Catalog 产品
<a name="step-2-create-blueprint-product"></a>

要创建 AWS Service Catalog 产品，请按照《*AWS Service Catalog 管理员指南》*中[创建产品](https://docs.aws.amazon.com//servicecatalog/latest/adminguide/productmgmt-cloudresource.html)中的步骤进行操作。创建 AWS Service Catalog 产品时，您需要将账户蓝图添加为模板。

**重要**  
*由于更新 HashiCorp了 Terraform 许可，将对 Terrafor *m 开源产品和预配置产品的支持 AWS Service Catalog 更改为一种名为 Exter* nal 的新产品类型。*要详细了解此更改对 AFC 的影响，包括如何将现有账户蓝图更新为 External 产品类型，请查看 [Transition to External product type](af-customization-page.md#service-catalog-external-product-type)。

**创建蓝图的步骤摘要**
+ 创建或下载 CloudFormation 模板或 Terraform tar.gz 配置文件，该文件将成为您的账户蓝图。本节稍后的部分将提供一些模板示例。
+ 登录您存储 Account Factory 蓝图 AWS 账户 的地方（有时称为中心账户）。
+ 导航到 AWS Service Catalog 控制台。选择**产品列表**，然后选择**上传新产品**。
+ 在**产品详细信息**窗格中，输入蓝图产品的详细信息，例如名称和描述。
+ 选择**使用模板文件**，然后选择**选择文件**。选择或粘贴您开发或下载的用作蓝图的模板或配置文件。
+ 选择控制台页面底部的**创建产品**。

 您可以从 AWS Service Catalog 参考架构存储库下载 CloudFormation 模板。[请查看该存储库中的一个示例，以帮助您针对您的资源制定备份计划](https://github.com/aws-samples/aws-service-catalog-reference-architectures/blob/master/backup/backup-tagoptions.yml)。

下面是一个示例模板，用于一家名为 **Best Pets** 的虚构公司。它可以帮助建立与公司宠物数据库的连接。

```
Resources:
  ConnectionStringGeneratorLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"		 	 	 
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
            Action:
              - "sts:AssumeRole"
  ConnectionStringGeneratorLambda:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: !Join ['-', ['ConnectionStringGenerator', !Select [4, !Split ['-', !Select [2, !Split ['/', !Ref AWS::StackId]]]]]]
      Description: Retrieves the connection string for this account to access the Pet Database
      Role: !GetAtt ConnectionStringGeneratorLambdaRole.Arn
      Runtime: nodejs22.x
      Handler: index.handler
      Timeout: 5
      Code:
        ZipFile: >
           export const handler = async (event, context) => {
             const awsAccountId = context.invokedFunctionArn.split(“:”)[4]
             const connectionString= “fake connection for account ” + awsAccountId;
             const response = {
               statusCode: 200,
               body: connectionString
             };
           return response;
          };

  ConnectionString:
    Type: Custom::ConnectionStringGenerator
    Properties:
      ServiceToken: !GetAtt ConnectionStringGeneratorLambda.Arn

  PetDatabaseConnectionString:
    DependsOn: ConnectionString
    # For example purposes we're using SSM parameter store.
    # In your template, use secure alternatives to store
    # sensitive values such as connection strings.
    Type: AWS::SSM::Parameter
    Properties: 
      Name: pet-database-connection-string
      Description: Connection information for the BestPets pet database
      Type: String
      Value: !GetAtt ConnectionString.Value
```