AWS CDK

イシュー

  • CICD環境構築をプログラミングできる aws-cdk について調べる

参考

はじめてのCDK deploy

$ cdk deploy
npx: 1個のパッケージを10.022秒でインストールしました。
Path must be a string. Received undefined
null
This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
Please confirm you intend to make the following modifications:

IAM Statement Changes
┌───┬─────────────────────────┬────────┬─────────────────────────┬─────────────────────────┬──────────────────────────┐
│   │ Resource                │ Effect │ Action                  │ Principal               │ Condition    │
├───┼─────────────────────────┼────────┼─────────────────────────┼─────────────────────────┼──────────────────────────┤
│ + │ ${multi-sample-Lambda.A │ Allow  │ lambda:InvokeFunction   │ Service:apigateway.amaz │ "ArnLike": {    │
│   │ rn}                     │        │                         │ onaws.com               │   "AWS:SourceArn": "arn: │
│   │                         │        │                         │                         │ ${AWS::Partition}:execut │
│   │                         │        │                         │                         │ e-api:${AWS::Region}:${A │
│   │                         │        │                         │                         │ WS::AccountId}:${multisa │
│   │                         │        │                         │                         │ mpleapiF1330A3B}/${multi │
│   │                         │        │                         │                         │ -sample-api/DeploymentSt │
│   │                         │        │                         │                         │ age.prod}/GET/message/{i │
│   │                         │        │                         │                         │ d}"    │
│   │                         │        │                         │                         │ }    │
│ + │ ${multi-sample-Lambda.A │ Allow  │ lambda:InvokeFunction   │ Service:apigateway.amaz │ "ArnLike": {    │
│   │ rn}                     │        │                         │ onaws.com               │   "AWS:SourceArn": "arn: │
│   │                         │        │                         │                         │ ${AWS::Partition}:execut │
│   │                         │        │                         │                         │ e-api:${AWS::Region}:${A │
│   │                         │        │                         │                         │ WS::AccountId}:${multisa │
│   │                         │        │                         │                         │ mpleapiF1330A3B}/test-in │
│   │                         │        │                         │                         │ voke-stage/GET/message/{ │
│   │                         │        │                         │                         │ id}"    │
│   │                         │        │                         │                         │ }    │
├───┼─────────────────────────┼────────┼─────────────────────────┼─────────────────────────┼──────────────────────────┤
│ + │ ${multi-sample-Lambda/S │ Allow  │ sts:AssumeRole          │ Service:lambda.amazonaw │    │
│   │ erviceRole.Arn}         │        │                         │ s.com                   │    │
├───┼─────────────────────────┼────────┼─────────────────────────┼─────────────────────────┼──────────────────────────┤
│ + │ ${multi-sample-api/Clou │ Allow  │ sts:AssumeRole          │ Service:apigateway.amaz │    │
│   │ dWatchRole.Arn}         │        │                         │ onaws.com               │    │
└───┴─────────────────────────┴────────┴─────────────────────────┴─────────────────────────┴──────────────────────────┘
IAM Policy Changes
┌───┬────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────┐
│   │ Resource                           │ Managed Policy ARN │
├───┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤
│ + │ ${multi-sample-Lambda/ServiceRole} │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecution │
│   │                                    │ Role │
├───┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤
│ + │ ${multi-sample-api/CloudWatchRole} │ arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonAPIGatewayPushToC │
│   │                                    │ loudWatchLogs │
└───┴────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘
(NOTE: There may be security-related changes not in this list. See http://bit.ly/cdk-2EhF7Np)

Do you wish to deploy these changes (y/n)? y
AwscdkMultiStackSampleStack: deploying...

 ❌  AwscdkMultiStackSampleStack failed: Error: This stack uses assets, so the toolkit stack must be deployed to the envi
ronment (Run "cdk bootstrap aws://unknown-account/unknown-region")
This stack uses assets, so the toolkit stack must be deployed to the environment (Run "cdk bootstrap aws://unknown-accou
nt/unknown-region")

$

Tutorial

MyWidgetService

resources/widgets.js

  • API Gateway上で動く)lambda

    lib/widget_service.ts

  • Cloudformationの定義

    lib/my_widget_service-stack.ts

  • 上で定義したCloudformationを呼び出し

App/Stack/Construct

CDK Workshop