-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate amplify-category-api to CDK v2 #883
Changes from all commits
888514e
8981992
ef0cbca
ddf3348
3f38013
f5ae578
c83472a
6e4bff1
5e6a3eb
37a5e64
2030083
8481425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import * as ecr from '@aws-cdk/aws-ecr'; | ||
import * as ecs from '@aws-cdk/aws-ecs'; | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import { CfnFunction } from '@aws-cdk/aws-lambda'; | ||
import * as logs from '@aws-cdk/aws-logs'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import * as ssm from '@aws-cdk/aws-secretsmanager'; | ||
import * as cloudmap from '@aws-cdk/aws-servicediscovery'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { prepareApp } from '@aws-cdk/core/lib/private/prepare-app'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import * as ecr from 'aws-cdk-lib/aws-ecr'; | ||
import * as ecs from 'aws-cdk-lib/aws-ecs'; | ||
import * as iam from 'aws-cdk-lib/aws-iam'; | ||
import { CfnFunction } from 'aws-cdk-lib/aws-lambda'; | ||
import * as logs from 'aws-cdk-lib/aws-logs'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as ssm from 'aws-cdk-lib/aws-secretsmanager'; | ||
import * as cloudmap from 'aws-cdk-lib/aws-servicediscovery'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { prepareApp } from 'aws-cdk-lib/core/lib/private/prepare-app'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove this import if its just building one cfn file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding follow up for this https://app.asana.com/0/1202389680978480/1203186729774450/f . We should revisit this when e2e tests are green. |
||
import { NETWORK_STACK_LOGICAL_ID } from '../../category-constants'; | ||
import Container from './docker-compose/ecs-objects/container'; | ||
import { GitHubSourceActionInfo, PipelineWithAwaiter } from './pipeline-with-awaiter'; | ||
|
@@ -74,7 +75,7 @@ export abstract class ContainersStack extends cdk.Stack { | |
protected readonly deploymentBucketName: string; | ||
protected readonly awaiterS3Key: string; | ||
|
||
constructor(scope: cdk.Construct, id: string, private readonly props: ContainersStackProps) { | ||
constructor(scope: Construct, id: string, private readonly props: ContainersStackProps) { | ||
super(scope, id); | ||
|
||
const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { | ||
$TSContext, | ||
$TSObject, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import * as apigw2 from '@aws-cdk/aws-apigatewayv2'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as apigw2 from 'aws-cdk-lib/aws-apigatewayv2'; | ||
import * as apigw2alpha from '@aws-cdk/aws-apigatewayv2-alpha'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this for constant definitions used below. We should be fine as this is internal usage. |
||
import * as cdk from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { ContainersStack, ContainersStackProps } from './base-api-stack'; | ||
import { API_TYPE } from './service-walkthroughs/containers-walkthrough'; | ||
|
||
|
@@ -9,7 +11,7 @@ type EcsStackProps = Readonly< | |
} | ||
>; | ||
export class EcsStack extends ContainersStack { | ||
constructor(scope: cdk.Construct, id: string, private readonly ecsProps: EcsStackProps) { | ||
constructor(scope: Construct, id: string, private readonly ecsProps: EcsStackProps) { | ||
super(scope, id, { | ||
...ecsProps, | ||
createCloudMapService: true, | ||
|
@@ -42,7 +44,7 @@ export class EcsStack extends ContainersStack { | |
corsConfiguration: { | ||
allowHeaders: ['*'], | ||
allowOrigins: ['*'], | ||
allowMethods: Object.values(apigw2.HttpMethod).filter(m => m !== apigw2.HttpMethod.ANY), | ||
allowMethods: Object.values(apigw2alpha.HttpMethod).filter(m => m !== apigw2alpha.HttpMethod.ANY), | ||
}, | ||
}); | ||
|
||
|
@@ -54,9 +56,9 @@ export class EcsStack extends ContainersStack { | |
|
||
const integration = new apigw2.CfnIntegration(this, 'ANYIntegration', { | ||
apiId: cdk.Fn.ref(api.logicalId), | ||
integrationType: apigw2.HttpIntegrationType.HTTP_PROXY, | ||
integrationType: apigw2alpha.HttpIntegrationType.HTTP_PROXY, | ||
connectionId: this.vpcLinkId, | ||
connectionType: apigw2.HttpConnectionType.VPC_LINK, | ||
connectionType: apigw2alpha.HttpConnectionType.VPC_LINK, | ||
integrationMethod: 'ANY', | ||
integrationUri: this.cloudMapService.attrArn, | ||
payloadFormatVersion: '1.0', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import * as codebuild from '@aws-cdk/aws-codebuild'; | ||
import * as codepipeline from '@aws-cdk/aws-codepipeline'; | ||
import * as codepipelineactions from '@aws-cdk/aws-codepipeline-actions'; | ||
import * as ecr from '@aws-cdk/aws-ecr'; | ||
import * as ecs from '@aws-cdk/aws-ecs'; | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import * as lambda from '@aws-cdk/aws-lambda'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as custom from '@aws-cdk/custom-resources'; | ||
import * as codebuild from 'aws-cdk-lib/aws-codebuild'; | ||
import * as codepipeline from 'aws-cdk-lib/aws-codepipeline'; | ||
import * as codepipelineactions from 'aws-cdk-lib/aws-codepipeline-actions'; | ||
import * as ecr from 'aws-cdk-lib/aws-ecr'; | ||
import * as ecs from 'aws-cdk-lib/aws-ecs'; | ||
import * as iam from 'aws-cdk-lib/aws-iam'; | ||
import * as lambda from 'aws-cdk-lib/aws-lambda'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as custom from 'aws-cdk-lib/custom-resources'; | ||
import { Construct } from 'constructs'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { DEPLOYMENT_MECHANISM } from './base-api-stack'; | ||
|
@@ -30,8 +31,8 @@ const lambdaRuntimeNodeVersion = lambda.Runtime.NODEJS_12_X; | |
|
||
const lambdasDir = path.resolve(__dirname, '../../../resources/awscloudformation/lambdas'); | ||
|
||
class PipelineAwaiter extends cdk.Construct { | ||
constructor(scope: cdk.Construct, id: string, props: PipelineAwaiterProps) { | ||
class PipelineAwaiter extends Construct { | ||
constructor(scope: Construct, id: string, props: PipelineAwaiterProps) { | ||
const { pipeline, artifactBucketName, artifactKey, deploymentMechanism } = props; | ||
|
||
const { pipelineArn, pipelineName } = pipeline; | ||
|
@@ -90,10 +91,10 @@ class PipelineAwaiter extends cdk.Construct { | |
} | ||
} | ||
|
||
export class PipelineWithAwaiter extends cdk.Construct { | ||
export class PipelineWithAwaiter extends Construct { | ||
pipelineName: string; | ||
constructor( | ||
scope: cdk.Construct, | ||
scope: Construct, | ||
id: string, | ||
{ | ||
skipWait = false, | ||
|
@@ -246,11 +247,17 @@ export class PipelineWithAwaiter extends cdk.Construct { | |
actions: [ | ||
new codepipelineactions.EcsDeployAction({ | ||
actionName: 'Deploy', | ||
service: new (class extends cdk.Construct implements ecs.IBaseService { | ||
service: new (class extends Construct implements ecs.IBaseService { | ||
// eslint-disable-next-line class-methods-use-this | ||
applyRemovalPolicy(_: cdk.RemovalPolicy): void { | ||
// NO-OP | ||
} | ||
|
||
Comment on lines
+250
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is forced upon us by |
||
cluster = { | ||
clusterName: service.cluster, | ||
env: {}, | ||
} as ecs.ICluster; | ||
|
||
serviceArn = cdk.Fn.ref(service.attrServiceArn); | ||
serviceName = service.serviceName; | ||
stack = cdk.Stack.of(this); | ||
|
@@ -292,7 +299,7 @@ export class PipelineWithAwaiter extends cdk.Construct { | |
} | ||
|
||
function createPreBuildStages( | ||
scope: cdk.Construct, | ||
scope: Construct, | ||
{ | ||
bucket, | ||
s3SourceActionKey, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of Because of https://app.circleci.com/pipelines/github/aws-amplify/amplify-category-api/1548/workflows/86e8aeb5-342e-4526-9370-2b7789e24d18/jobs/40319 .
I .
Borrowed from https://github.com/aws-amplify/amplify-cli/blob/015187a8b714b96fbb87331383a92664aa6e6f35/.circleci/config.base.yml#L134-L148