

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

# 在基础架构编排器中创建引用外部文件的应用程序
<a name="using-composer-external-files-examples-example3"></a>

此示例使用创建了一个引用外部文件作为其状态机定义的应用程序。 AWS SAMCLI然后，在基础架构编排器中加载项目，并正确引用外部文件。

**示例**

1. 首先，使用 AWS SAM CLI **sam init** 命令初始化名为的新应用程序`demo`。在交互流程中，选择**多步骤工作流**快速入门模板。

   ```
   $ sam init
   
   ...
   
   Which template source would you like to use?
           1 - AWS Quick Start Templates
           2 - Custom Template Location
   Choice: {{1}}
   
   Choose an AWS Quick Start application template
           1 - Hello World Example
           2 - Multi-step workflow
           3 - Serverless API
           4 - Scheduled task
           ...
   Template: {{2}}
   
   Which runtime would you like to use?
           1 - dotnet6
           2 - dotnetcore3.1
           ...
           15 - python3.7
           16 - python3.10
           17 - ruby2.7
   Runtime: {{16}}
   
   Based on your selections, the only Package type available is Zip.
   We will proceed to selecting the Package type as Zip.
   
   Based on your selections, the only dependency manager available is pip.
   We will proceed copying the template using pip.
   
   Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: {{ENTER}}
   
   Would you like to enable monitoring using CloudWatch Application Insights?
   For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: {{ENTER}}
   
   Project name [sam-app]: {{demo}}
   
       -----------------------
       Generating application:
       -----------------------
       Name: demo
       Runtime: python3.10
       Architectures: x86_64
       Dependency Manager: pip
       Application Template: step-functions-sample-app
       Output Directory: .
       Configuration file: demo/samconfig.toml
       
       Next steps can be found in the README file at demo/README.md
   
   ...
   ```

   此应用程序引用状态机定义的外部文件。

   ```
   ...
   Resources:
     StockTradingStateMachine:
       Type: AWS::Serverless::StateMachine
       Properties:
         DefinitionUri: statemachine/stock_trader.asl.json
   ...
   ```

   外部文件位于我们应用程序的`statemachine`子目录中。

   ```
   demo
   ├── README.md
   ├── __init__.py
   ├── functions
   │   ├── __init__.py
   │   ├── stock_buyer
   │   ├── stock_checker
   │   └── stock_seller
   ├── samconfig.toml
   ├── statemachine
   │   └── stock_trader.asl.json
   ├── template.yaml
   └── tests
   ```

1. 接下来，从控制台在基础设施编排器中加载您的应用程序。在基础设施编排器**主页**上，选择**加载CloudFormation 模板**。

1. 选择我们的`demo`项目文件夹，然后允许提示查看文件。选择我们的`template.yaml`文件并选择 “**创建**”。出现提示时，选择**保存更改**。  
![Infrastructure Composer “打开项目文件夹” 窗口，选中我们的项目文件夹，“创建” 准备就绪。](http://docs.aws.amazon.com/zh_cn/infrastructure-composer/latest/dg/images/aac_use_ex_15.png)

基础架构 Composer 会自动检测外部状态机定义文件并将其加载。选择我们的**StockTradingStateMachine**资源并选择**详细信息**以显示**资源属性**面板。在这里，您可以看到基础设施编排器已自动连接到我们的外部状态机定义文件。

![显示了 API Gateway 资源属性面板的 Infrastructure Composer 画布视图，显示了外部参考文件的配置。](http://docs.aws.amazon.com/zh_cn/infrastructure-composer/latest/dg/images/aac_use_ex_03.png)


对状态机定义文件所做的任何更改都将自动反映在基础设施编排器中。