Skip to content
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

Merged
merged 12 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ jobs:
- run:
name: Collect code coverage
command: yarn coverage
environment:
NODE_OPTIONS: --max-old-space-size=4096
Comment on lines 99 to +101
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


lint:
<<: *linux-e2e-executor
Expand Down
75 changes: 17 additions & 58 deletions packages/amplify-category-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/amplify-category-api",
"version": "4.0.5",
"version": "5.0.0",
"description": "Amplify CLI API category plugin",
"repository": {
"type": "git",
Expand Down Expand Up @@ -28,66 +28,26 @@
"access": "public"
},
"dependencies": {
"@aws-amplify/graphql-auth-transformer": "1.1.0",
"@aws-amplify/graphql-default-value-transformer": "0.7.0",
"@aws-amplify/graphql-function-transformer": "0.7.28",
"@aws-amplify/graphql-http-transformer": "0.8.28",
"@aws-amplify/graphql-index-transformer": "0.14.0",
"@aws-amplify/graphql-maps-to-transformer": "1.1.31",
"@aws-amplify/graphql-model-transformer": "0.16.0",
"@aws-amplify/graphql-predictions-transformer": "0.6.28",
"@aws-amplify/graphql-relational-transformer": "0.12.0",
"@aws-amplify/graphql-searchable-transformer": "0.16.0",
"@aws-amplify/graphql-transformer-core": "0.17.12",
"@aws-amplify/graphql-transformer-interfaces": "1.14.7",
"@aws-amplify/graphql-transformer-migrator": "1.4.7",
"@aws-cdk/assets": "~1.124.0",
"@aws-cdk/aws-apigateway": "~1.124.0",
"@aws-cdk/aws-apigatewayv2": "~1.124.0",
"@aws-cdk/aws-applicationautoscaling": "~1.124.0",
"@aws-cdk/aws-autoscaling": "~1.124.0",
"@aws-cdk/aws-autoscaling-hooktargets": "~1.124.0",
"@aws-cdk/aws-certificatemanager": "~1.124.0",
"@aws-cdk/aws-cloudformation": "~1.124.0",
"@aws-cdk/aws-cloudfront": "~1.124.0",
"@aws-cdk/aws-cloudwatch": "~1.124.0",
"@aws-cdk/aws-codebuild": "~1.124.0",
"@aws-cdk/aws-codeguruprofiler": "~1.124.0",
"@aws-cdk/aws-codepipeline": "~1.124.0",
"@aws-cdk/aws-codepipeline-actions": "~1.124.0",
"@aws-cdk/aws-cognito": "~1.124.0",
"@aws-cdk/aws-ec2": "~1.124.0",
"@aws-cdk/aws-ecr": "~1.124.0",
"@aws-cdk/aws-ecr-assets": "~1.124.0",
"@aws-cdk/aws-ecs": "~1.124.0",
"@aws-cdk/aws-efs": "~1.124.0",
"@aws-cdk/aws-elasticloadbalancing": "~1.124.0",
"@aws-cdk/aws-elasticloadbalancingv2": "~1.124.0",
"@aws-cdk/aws-events": "~1.124.0",
"@aws-cdk/aws-iam": "~1.124.0",
"@aws-cdk/aws-kms": "~1.124.0",
"@aws-cdk/aws-lambda": "~1.124.0",
"@aws-cdk/aws-logs": "~1.124.0",
"@aws-cdk/aws-route53": "~1.124.0",
"@aws-cdk/aws-route53-targets": "~1.124.0",
"@aws-cdk/aws-s3": "~1.124.0",
"@aws-cdk/aws-s3-assets": "~1.124.0",
"@aws-cdk/aws-secretsmanager": "~1.124.0",
"@aws-cdk/aws-servicediscovery": "~1.124.0",
"@aws-cdk/aws-sns": "~1.124.0",
"@aws-cdk/aws-sns-subscriptions": "~1.124.0",
"@aws-cdk/aws-sqs": "~1.124.0",
"@aws-cdk/aws-ssm": "~1.124.0",
"@aws-cdk/cloud-assembly-schema": "~1.124.0",
"@aws-cdk/core": "~1.124.0",
"@aws-cdk/custom-resources": "~1.124.0",
"@aws-cdk/cx-api": "~1.124.0",
"@aws-cdk/region-info": "~1.124.0",
"@aws-amplify/graphql-auth-transformer": "2.0.0",
"@aws-amplify/graphql-default-value-transformer": "1.0.0",
"@aws-amplify/graphql-function-transformer": "1.0.0",
"@aws-amplify/graphql-http-transformer": "1.0.0",
"@aws-amplify/graphql-index-transformer": "1.0.0",
"@aws-amplify/graphql-maps-to-transformer": "2.0.0",
"@aws-amplify/graphql-model-transformer": "1.0.0",
"@aws-amplify/graphql-predictions-transformer": "1.0.0",
"@aws-amplify/graphql-relational-transformer": "1.0.0",
"@aws-amplify/graphql-searchable-transformer": "1.0.0",
"@aws-amplify/graphql-transformer-core": "1.0.0",
"@aws-amplify/graphql-transformer-interfaces": "2.0.0",
"@aws-amplify/graphql-transformer-migrator": "2.0.0",
"aws-cdk-lib": "^2.41.0",
"@aws-cdk/aws-apigatewayv2-alpha": "^2.41.0-alpha.0",
"constructs": "^10.0.5",
"@graphql-tools/merge": "^6.0.18",
"@octokit/rest": "^18.0.9",
"chalk": "^4.1.1",
"cloudform": "^4.2.0",
"constructs": "^3.3.125",
"fs-extra": "^8.1.0",
"graphql": "^14.5.8",
"graphql-auth-transformer": "7.2.44",
Expand Down Expand Up @@ -119,7 +79,6 @@
"amplify-util-headless-input": "^1.9.5"
},
"devDependencies": {
"@aws-cdk/assertions": "~1.124.0",
"@types/js-yaml": "^4.0.0",
"amplify-util-headless-input": "^1.9.5"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cdk from '@aws-cdk/core';
import { Template } from '@aws-cdk/assertions';
import * as cdk from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { AmplifyApigwResourceStack } from '../../../../provider-utils/awscloudformation/cdk-stack-builder/apigw-stack-builder';
import { PermissionSetting } from '../../../../provider-utils/awscloudformation/cdk-stack-builder/types';

Expand Down
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';
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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';
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
/* eslint-disable no-use-before-define */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable no-underscore-dangle */
import * as apigw from '@aws-cdk/aws-apigateway';
import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import * as apigw from 'aws-cdk-lib/aws-apigateway';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as cdk from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { $TSObject, JSONUtilities } from 'amplify-cli-core';
import _ from 'lodash';
import { v4 as uuid } from 'uuid';
Expand All @@ -23,13 +24,13 @@ export class AmplifyApigwResourceStack extends cdk.Stack implements AmplifyApigw
deploymentResource: apigw.CfnDeployment;
paths: $TSObject;
policies: { [pathName: string]: ApigwPathPolicy };
private _scope: cdk.Construct;
private _scope: Construct;
private _props: ApigwInputs;
private _cfnParameterMap: Map<string, cdk.CfnParameter> = new Map();
private _cfnParameterValues: $TSObject;
private _seenLogicalIds: Set<string>;

constructor(scope: cdk.Construct, id: string, props: ApigwInputs) {
constructor(scope: Construct, id: string, props: ApigwInputs) {
super(scope, id, undefined);
this._scope = scope;
this._props = props;
Expand Down Expand Up @@ -244,7 +245,7 @@ export class AmplifyApigwResourceStack extends cdk.Stack implements AmplifyApigw
},
});

// Append a random id to the logical id of the gateway response
// Append a random id to the logical id of the gateway response
// This is required to resolve issue with dropping gateway responses on updating api resource
const [responseRandomId] = uuid().split('-');
const default4xx = new apigw.CfnGatewayResponse(this, `${resourceName}Default4XXResponse${responseRandomId}`, {
Expand Down
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cdk from '@aws-cdk/core';
import * as apigwCdk from '@aws-cdk/aws-apigateway';
import * as iamCdk from '@aws-cdk/aws-iam';
import * as cdk from 'aws-cdk-lib';
import * as apigwCdk from 'aws-cdk-lib/aws-apigateway';
import * as iamCdk from 'aws-cdk-lib/aws-iam';

export type ApigwInputs = {
version: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as acm from '@aws-cdk/aws-certificatemanager';
import * as cloudfront from '@aws-cdk/aws-cloudfront';
import * as cognito from '@aws-cdk/aws-cognito';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as elb2 from '@aws-cdk/aws-elasticloadbalancingv2';
import * as route53 from '@aws-cdk/aws-route53';
import * as route53targets from '@aws-cdk/aws-route53-targets';
import * as cdk from '@aws-cdk/core';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as cognito from 'aws-cdk-lib/aws-cognito';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as elb2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as route53targets from 'aws-cdk-lib/aws-route53-targets';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { v4 as uuid } from 'uuid';
import { ContainersStack, ContainersStackProps } from './base-api-stack';

Expand All @@ -19,7 +20,7 @@ type EcsStackProps = ContainersStackProps &
export class EcsAlbStack extends ContainersStack {
private readonly userPoolDomain: string;

constructor(scope: cdk.Construct, id: string, private readonly ecsProps: EcsStackProps) {
constructor(scope: Construct, id: string, private readonly ecsProps: EcsStackProps) {
super(scope, id, {
...ecsProps,
skipWait: true,
Expand Down
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';
Copy link
Member Author

Choose a reason for hiding this comment

The 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.
The alternative is to copy constants into our codebase and maintain them.

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';

Expand All @@ -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,
Expand Down Expand Up @@ -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),
},
});

Expand All @@ -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',
Expand Down
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';
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is forced upon us by cdk.IResource . I have not found an obvious candidate to delegate this call to this anonymous class members (or containing class). Therefore I'm logging follow up for this here . https://app.asana.com/0/1202389680978480/1203167795285200/f .

See https://github.com/aws/aws-cdk/blob/4525be85ff89a9606b5891d5a5a33438e57460e2/packages/%40aws-cdk/core/lib/resource.ts#L61-L72

cluster = {
clusterName: service.cluster,
env: {},
} as ecs.ICluster;

serviceArn = cdk.Fn.ref(service.attrServiceArn);
serviceName = service.serviceName;
stack = cdk.Stack.of(this);
Expand Down Expand Up @@ -292,7 +299,7 @@ export class PipelineWithAwaiter extends cdk.Construct {
}

function createPreBuildStages(
scope: cdk.Construct,
scope: Construct,
{
bucket,
s3SourceActionKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Duration, Expiration } from '@aws-cdk/core';
import { Duration, Expiration } from 'aws-cdk-lib';
import {
$TSContext,
$TSObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { $TSAny, $TSContext, JSONUtilities, pathManager, readCFNTemplate } from
import { DEPLOYMENT_MECHANISM } from '../base-api-stack';
import { setExistingSecretArns } from './containers/set-existing-secret-arns';
import { category } from '../../../category-constants';
import * as cdk from '@aws-cdk/core';
import * as cdk from 'aws-cdk-lib';

export const cfnFileName = (resourceName: string) => `${resourceName}-cloudformation-template.json`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $TSAny } from 'amplify-cli-core';
import _ from 'lodash';
import * as cdk from '@aws-cdk/core';
import * as cdk from 'aws-cdk-lib';

/**
* Check if the template contains existing secret configuration and if so, add it to the secretsMap
Expand Down
Loading