修改项目以使用自定义容器 - AWS SimSpace Weaver

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

修改项目以使用自定义容器

这些说明假设您已经知道如何使用, AWS SimSpace Weaver 并希望提高应用程序存储和开发工作流程的 AWS Cloud 效率。

先决条件
  • 在 Amazon Elastic Container Registry (Amazon ECR) 中有一个自定义容器。有关创建自定义容器的更多信息,请参阅创建自定义容器

修改项目以使用自定义容器
  1. 为项目的模拟应用程序角色添加使用 Amazon ECR 的权限。

    1. 如果您目前没有具有以下权限的 IAM 策略,请创建该策略。我们建议使用策略名称 simspaceweaver-ecr。有关如何创建 IAM 策略的更多信息,请参阅《AWS Identity and Access Management 用户指南》中的创建 IAM 策略

      { "Version": "2012-10-17", "Statement": [ { "Sid": "Statement", "Effect": "Allow", "Action": [ "ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer", "ecr:GetAuthorizationToken" ], "Resource": "*" } ] }
    2. 查找项目的模拟应用程序角色的名称:

      1. 在文本编辑器中,打开 AWS CloudFormation 模板:

        sdk-folder\PackagingTools\sample-stack-template.yaml
      2. WeaverAppRole 下找到 RoleName 属性。该值是项目的模拟应用程序角色的名称。

        AWSTemplateFormatVersion: "2010-09-09" Resources: WeaverAppRole: Type: 'AWS::IAM::Role' Properties: RoleName: 'weaver-MySimulation-app-role' AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: Service: - 'simspaceweaver.amazonaws.com'
    3. simspaceweaver-ecr 策略附加到项目的模拟应用程序角色。有关如何附加策略的更多信息,请参阅《AWS Identity and Access Management 用户指南》中的添加和删除 IAM 身份权限

    4. 导航到sdk-folder并运行以下命令以更新示例 SimSpace Weaver 堆栈:

      python setup.py --cloudformation
  2. 在项目的模拟架构中指定您的容器映像。

    • 您可以在 simulation_properties 下添加可选 default_image 属性,为所有域指定默认的自定义容器映像。

    • app_config 中为要使用自定义容器映像的域添加 image 属性。指定 Amazon ECR 存储库 URI 作为值。您可以为每个域指定不同的映像。

      • 如果没有为域指定 image,但已指定 default_image,则该域中的应用程序将使用默认映像。

      • 如果image未为网域指定且default_image未指定,则该网域中的应用程序将在标准 SimSpace Weaver 容器中运行。

    例 包含自定义容器设置的架构片段
    sdk_version: "1.17.0" simulation_properties: log_destination_service: "logs" log_destination_resource_name: "MySimulationLogs" default_entity_index_key_type: "Vector3<f32>" default_image: "111122223333.dkr.ecr.us-west-2.amazonaws.com/my-ecr-repository:latest" # image to use if no image specified for a domain domains: MyCustomDomain: launch_apps_via_start_app_call: {} app_config: package: "s3://weaver-myproject-111122223333-us-west-2/MyViewApp.zip" launch_command: ["MyViewApp"] required_resource_units: compute: 1 endpoint_config: ingress_ports: - 7000 image: "111122223333.dkr.ecr.us-west-2.amazonaws.com/my-ecr-repository:latest" # custom container image to use for this domain MySpatialDomain: launch_apps_by_partitioning_strategy: partitioning_strategy: "MyGridPartitioning" grid_partition: x: 2 y: 2 app_config: package: "s3://weaver-myproject-111122223333-us-west-2/MySpatialApp.zip" launch_command: ["MySpatialApp"] required_resource_units: compute: 1 image: "111122223333.dkr.ecr.us-west-2.amazonaws.com/my-ecr-repository:latest" # custom container image to use for this domain
  3. 照常构建和上传项目。