CodeBuild プロビジョニングテンプレートバンドル - AWS Proton

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

CodeBuild プロビジョニングテンプレートバンドル

CodeBuild プロビジョニングでは、IaC テンプレートを使用して IaC ファイルをレンダリングし、IaC プロビジョニングエンジンを使用して実行する代わりに、 AWS Proton シェルコマンドを単純に実行します。そのために、 は環境の AWS CodeBuild プロジェクトを環境アカウントで AWS Proton 作成し、 AWS Proton リソースの作成または更新ごとにコマンドを実行するジョブを開始します。テンプレートバンドルをオーサリングするとき、インフラストラクチャのプロビジョニングコマンドとデプロビジョニングコマンド、およびこれらのコマンドに必要なプログラム、スクリプト、その他のファイルを指定するマニフェストは、あなたが提供してください。あなたのコマンドでは、 AWS Proton が提供する入力を読み取ることができ、インフラのプロビジョニングまたはデプロビジョニングを行い、出力値を生成します。

マニフェスト AWS Proton は、コードが入力して入力値を取得できる入力ファイルを がレンダリングする方法も指定します。JSON または HCL にレンダリングできます。入力パラメータの詳細については、「CodeBuild プロビジョニングパラメータの詳細と例」を参照してください。マニフェストファイルについて詳しくは、「のテンプレートファイルをまとめる AWS Proton」を参照してください。

注記

CodeBuild プロビジョニングは環境とサービスで使用できます。現時点では、この方法でコンポーネントをプロビジョニングすることはできません。

例: CodeBuild プロビジョニング AWS CDK で を使用する

CodeBuild プロビジョニングを使用する例として、 を使用して AWS リソース AWS Cloud Development Kit (AWS CDK) をプロビジョニング (デプロイ) およびプロビジョニング解除 (破棄) するコードと、CDK をインストールして CDK コードを実行するマニフェストを含めることができます。

以下のセクションでは、 AWS CDKで、プロビジョニングする CodeBuild プロビジョニングテンプレートバンドルに環境を組み込むことができるサンプルファイルの一覧を示します。

次のマニフェストファイルは CodeBuild プロビジョニングを指定し、 のインストールと使用 AWS CDK、出力ファイル処理、および出力のレポートに必要なコマンドが含まれています AWS Proton。

例 infrastructure/manifest.yaml
infrastructure: templates: - rendering_engine: codebuild settings: image: aws/codebuild/amazonlinux2-x86_64-standard:4.0 runtimes: nodejs: 16 provision: - npm install - npm run build - npm run cdk bootstrap - npm run cdk deploy -- --require-approval never --outputs-file proton-outputs.json - jq 'to_entries | map_values(.value) | add | to_entries | map({key:.key, valueString:.value})' < proton-outputs.json > outputs.json - aws proton notify-resource-deployment-status-change --resource-arn $RESOURCE_ARN --status IN_PROGRESS --outputs file://./outputs.json deprovision: - npm install - npm run build - npm run cdk destroy project_properties: VpcConfig: VpcId: "{{ environment.inputs.codebuild_vpc_id }}" Subnets: "{{ environment.inputs.codebuild_subnets }}" SecurityGroupIds: "{{ environment.inputs.codebuild_security_groups }}"

次のスキーマファイルは環境のパラメータを定義します。 AWS CDK コードは、デプロイ中にこれらのパラメータの値を参照できます。

例 schema/schema.yaml
schema: format: openapi: "3.0.0" environment_input_type: "MyEnvironmentInputType" types: MyEnvironmentInputType: type: object description: "Input properties for my environment" properties: my_sample_input: type: string description: "This is a sample input" default: "hello world" my_other_sample_input: type: string description: "Another sample input" required: - my_other_sample_input

以下のファイルは Node.js CDK プロジェクトの例です。

例 infrastructure/package.json
{ "name": "ProtonEnvironment", "version": "0.1.0", "bin": { "ProtonEnvironmente": "bin/ProtonEnvironment.js" }, "scripts": { "build": "tsc", "watch": "tsc -w", "test": "jest", "cdk": "cdk" }, "devDependencies": { "@types/jest": "^28.1.7", "@types/node": "18.7.6", "jest": "^28.1.3", "ts-jest": "^28.0.8", "aws-cdk": "2.37.1", "ts-node": "^10.9.1", "typescript": "~4.7.4" }, "dependencies": { "aws-cdk-lib": "2.37.1", "constructs": "^10.1.77", "source-map-support": "^0.5.21" } }
例 infrastructure/tsconfig.json
{ "compilerOptions": { "target": "ES2018", "module": "commonjs", "lib": [ "es2018" ], "declaration": true, "strict": true, "noImplicitAny": true, "strictNullChecks": true, "noImplicitThis": true, "alwaysStrict": true, "noUnusedLocals": false, "noUnusedParameters": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": false, "inlineSourceMap": true, "inlineSources": true, "experimentalDecorators": true, "strictPropertyInitialization": false, "resolveJsonModule": true, "esModuleInterop": true, "typeRoots": [ "./node_modules/@types" ] }, "exclude": [ "node_modules", "cdk.out" ] }
例 infrastructure/cdk.json
{ "app": "npx ts-node --prefer-ts-exts bin/ProtonEnvironment.ts", "outputsFile": "proton-outputs.json", "watch": { "include": [ "**" ], "exclude": [ "README.md", "cdk*.json", "**/*.d.ts", "**/*.js", "tsconfig.json", "package*.json", "yarn.lock", "node_modules", "test" ] }, "context": { "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, "@aws-cdk/core:stackRelativeExports": true, "@aws-cdk/aws-rds:lowercaseDbIdentifier": true, "@aws-cdk/aws-lambda:recognizeVersionProps": true, "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, "@aws-cdk/core:target-partitions": [ "aws", "aws-cn" ] } }
例 infrastructure/bin/ProtonEnvironment.ts
#!/usr/bin/env node import 'source-map-support/register'; import * as cdk from 'aws-cdk-lib'; import { ProtonEnvironmentStack } from '../lib/ProtonEnvironmentStack'; const app = new cdk.App(); new ProtonEnvironmentStack(app, 'ProtonEnvironmentStack', {});
例 infrastructure/lib/ProtonEnvironmentStack.ts
import { Stack, StackProps } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import * as cdk from 'aws-cdk-lib'; import * as ssm from 'aws-cdk-lib/aws-ssm'; import input from '../proton-inputs.json'; export class ProtonEnvironmentStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, { ...props, stackName: process.env.STACK_NAME }); const ssmParam = new ssm.StringParameter(this, "ssmParam", { stringValue: input.environment.inputs.my_sample_input, parameterName: `${process.env.STACK_NAME}-Param`, tier: ssm.ParameterTier.STANDARD }) new cdk.CfnOutput(this, 'ssmParamOutput', { value: ssmParam.parameterName, description: 'The name of the ssm parameter', exportName: `${process.env.STACK_NAME}-Param` }); } }

CodeBuild ベースのプロビジョニングテンプレートで環境を作成すると、 AWS Proton では、指定した入力パラメータ値を含む入力ファイルがレンダリングされます。これらの値はあなたのコードで参照できます。次のファイルは、レンダリングされた入力ファイルの例です。

例 infrastructure/proton-inputs.json
{ "environment": { "name": "myenv", "inputs": { "my_sample_input": "10.0.0.0/16", "my_other_sample_input": "11.0.0.0/16" } } }