

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Infrastructure Composer で外部ファイルを参照するアプリケーションを作成する
<a name="using-composer-external-files-examples-example3"></a>

この例では、 AWS SAM CLIを使用して、ステートマシン定義の外部ファイルを参照するアプリケーションを作成します。次に、外部ファイルが適切に参照された状態で Infrastructure Composer にプロジェクトをロードします。

**例**

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. 次に、コンソールから Infrastructure Composer にアプリケーションをロードします。Infrastructure Composer **ホームページ**から、**CloudFormation テンプレートのロード**を選択します。

1. `demo` プロジェクトフォルダを選択し、プロンプトにファイルの表示を許可します。`template.yaml` ファイルを選択し、**作成**を選択します。プロンプトが表示されたら、**変更の保存**を選択します。  
![Infrastructure Composer Open project folder window with our project folder selected and the Create ready to be selected。](http://docs.aws.amazon.com/ja_jp/infrastructure-composer/latest/dg/images/aac_use_ex_15.png)

Infrastructure Composer は、外部ステートマシン定義ファイルを自動的に検出してロードします。**StockTradingStateMachine** リソースを選択し、**詳細**を選択して**リソースプロパティ**パネルを表示します。ここでは、Infrastructure Composer が外部ステートマシン定義ファイルに自動的に接続されていることを確認できます。

![API Gateway リソースプロパティパネルが表示された Infrastructure Composer キャンバスビュー。外部リファレンスファイルの設定が表示されます。](http://docs.aws.amazon.com/ja_jp/infrastructure-composer/latest/dg/images/aac_use_ex_03.png)


ステートマシン定義ファイルに加えられた変更は、Infrastructure Composer に自動的に反映されます。