diff --git a/packages/amplify-category-auth/resources/overrides-resource/override.ts.sample b/packages/amplify-category-auth/resources/overrides-resource/override.ts.sample index 90f448f3ce8..79386f9750c 100644 --- a/packages/amplify-category-auth/resources/overrides-resource/override.ts.sample +++ b/packages/amplify-category-auth/resources/overrides-resource/override.ts.sample @@ -1,3 +1,5 @@ import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper'; -export function override(resources: AmplifyAuthCognitoStackTemplate) {} +export function override(resources: AmplifyAuthCognitoStackTemplate) { + +} diff --git a/packages/amplify-category-auth/resources/overrides-resource/package.json b/packages/amplify-category-auth/resources/overrides-resource/package.json index e239be79c23..7840a7020ae 100644 --- a/packages/amplify-category-auth/resources/overrides-resource/package.json +++ b/packages/amplify-category-auth/resources/overrides-resource/package.json @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@aws-amplify/cli-extensibility-helper": "1.0.1-ext15.0" + "@aws-amplify/cli-extensibility-helper": "latest" }, "devDependencies": { "typescript": "^4.2.4" diff --git a/packages/amplify-category-custom/resources/cdk-stack.ts b/packages/amplify-category-custom/resources/cdk-stack.ts.sample similarity index 51% rename from packages/amplify-category-custom/resources/cdk-stack.ts rename to packages/amplify-category-custom/resources/cdk-stack.ts.sample index 44828168cd9..0048b59f311 100644 --- a/packages/amplify-category-custom/resources/cdk-stack.ts +++ b/packages/amplify-category-custom/resources/cdk-stack.ts.sample @@ -1,12 +1,15 @@ import * as cdk from '@aws-cdk/core'; +import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper'; +import { AmplifyDependentResourcesAttributes } from '../../types/amplify-dependent-resources-ref'; /*import * as iam from '@aws-cdk/aws-iam'; import * as sns from '@aws-cdk/aws-sns'; import * as subs from '@aws-cdk/aws-sns-subscriptions'; import * as sqs from '@aws-cdk/aws-sqs'; */ + export class cdkStack extends cdk.Stack { - constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { + constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps, amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps) { super(scope, id, props); /* Do not remove - Amplify CLI automatically injects the current deployment environment in this input paramater */ @@ -16,13 +19,24 @@ export class cdkStack extends cdk.Stack { }); /* AWS CDK Code goes here - Learn more: https://docs.aws.amazon.com/cdk/latest/guide/home.html */ + /* Example 1: Set up an SQS queue with an SNS topic - const queue = new sqs.Queue(this, 'sqs-queue'); + const amplifyProjectInfo = AmplifyHelpers.getProjectInfo(); + + const sqsQueueResourceNamePrefix = `sqs-queue-${amplifyProjectInfo.projectName}`; + + const queue = new sqs.Queue(this, 'sqs-queue', { + queueName: cdk.Fn.join('-', [sqsQueueResourceNamePrefix, cdk.Fn.ref('env')]) + }); // 👇 create sns topic - const topic = new sns.Topic(this, 'sns-topic'); + + const snsTopicResourceNamePrefix = `sns-topic-${amplifyProjectInfo.projectName}`; + const topic = new sns.Topic(this, 'sns-topic', { + topicName: cdk.Fn.join('-', [snsTopicResourceNamePrefix, cdk.Fn.ref('env')]) + }); // 👇 subscribe queue to topic topic.addSubscription(new subs.SqsSubscription(queue)); @@ -34,9 +48,14 @@ export class cdkStack extends cdk.Stack { */ /* Example 2: Adding IAM role to the custom stack + + const roleResourceNamePrefix = `CustomRole-${amplifyProjectInfo.projectName}`; + const role = new iam.Role(this, 'CustomRole', { assumedBy: new iam.AccountRootPrincipal(), + roleName: cdk.Fn.join('-', [roleResourceNamePrefix, cdk.Fn.ref('env')]) }); + */ /* Example 3: Adding policy to the IAM role @@ -47,5 +66,18 @@ export class cdkStack extends cdk.Stack { }), ); */ + + /* Access other Amplify Resources + + const retVal:AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this, + amplifyResourceProps.category, + amplifyResourceProps.resourceName, + [ + {category: , resourceName: }, + ] + ); + + */ + } } diff --git a/packages/amplify-category-custom/resources/package.json b/packages/amplify-category-custom/resources/package.json index a5ab46463fd..58e743f3da0 100644 --- a/packages/amplify-category-custom/resources/package.json +++ b/packages/amplify-category-custom/resources/package.json @@ -8,8 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@types/fs-extra": "^9.0.11", - "fs-extra": "^9.1.0", + "@aws-amplify/cli-extensibility-helper": "latest", "@aws-cdk/core": "~1.124.0", "@aws-cdk/aws-iam": "~1.124.0", "@aws-cdk/aws-sns-subscriptions": "~1.124.0", diff --git a/packages/amplify-category-custom/src/index.ts b/packages/amplify-category-custom/src/index.ts index e591fe456a3..3654a136953 100644 --- a/packages/amplify-category-custom/src/index.ts +++ b/packages/amplify-category-custom/src/index.ts @@ -5,6 +5,7 @@ import { buildCustomResources } from './utils/build-custom-resources'; import { categoryName } from './utils/constants'; export { addCDKResourceDependency } from './utils/dependency-management-utils'; export { generateDependentResourcesType } from './utils/build-custom-resources'; +export { AmplifyResourceProps } from './utils/generate-cfn-from-cdk'; export async function executeAmplifyCommand(context: $TSContext) { let commandPath = path.normalize(path.join(__dirname, 'commands')); diff --git a/packages/amplify-category-custom/src/utils/generate-cfn-from-cdk.ts b/packages/amplify-category-custom/src/utils/generate-cfn-from-cdk.ts index 384f02381e4..33e06d891bc 100644 --- a/packages/amplify-category-custom/src/utils/generate-cfn-from-cdk.ts +++ b/packages/amplify-category-custom/src/utils/generate-cfn-from-cdk.ts @@ -3,11 +3,18 @@ import * as cdk from '@aws-cdk/core'; import { JSONUtilities, pathManager } from 'amplify-cli-core'; import { categoryName } from './constants'; +export type AmplifyResourceProps = { + category: string; + resourceName: string; +}; + export async function generateCloudFormationFromCDK(resourceName: string) { const targetDir = pathManager.getResourceDirectoryPath(undefined, categoryName, resourceName); const { cdkStack } = await import(path.resolve(path.join(targetDir, 'build', 'cdk-stack.js'))); - const customStack: cdk.Stack = new cdkStack(undefined, undefined, undefined, { category: categoryName, resourceName }); + const amplifyResourceProps: AmplifyResourceProps = { category: categoryName, resourceName }; + + const customStack: cdk.Stack = new cdkStack(undefined, undefined, undefined, amplifyResourceProps); // @ts-ignore JSONUtilities.writeJson(path.join(targetDir, 'build', `${resourceName}-cloudformation-template.json`), customStack._toCloudFormation()); diff --git a/packages/amplify-category-custom/src/walkthroughs/cdk-walkthrough.ts b/packages/amplify-category-custom/src/walkthroughs/cdk-walkthrough.ts index 8db106da294..899680647f0 100644 --- a/packages/amplify-category-custom/src/walkthroughs/cdk-walkthrough.ts +++ b/packages/amplify-category-custom/src/walkthroughs/cdk-walkthrough.ts @@ -56,5 +56,5 @@ async function generateSkeletonDir(resourceName: string) { } const cdkFilepath = path.join(targetDir, 'cdk-stack.ts'); - fs.writeFileSync(cdkFilepath, fs.readFileSync(path.join(srcResourceDirPath, 'cdk-stack.ts'))); + fs.writeFileSync(cdkFilepath, fs.readFileSync(path.join(srcResourceDirPath, 'cdk-stack.ts.sample'))); } diff --git a/packages/amplify-category-custom/tsconfig.json b/packages/amplify-category-custom/tsconfig.json index 1b5c94e8072..2be06f08c17 100644 --- a/packages/amplify-category-custom/tsconfig.json +++ b/packages/amplify-category-custom/tsconfig.json @@ -13,6 +13,7 @@ "references": [ {"path": "../amplify-cli-core"}, {"path": "../amplify-prompts"}, + {"path": "../amplify-cli-extensibility-helper"} ] } \ No newline at end of file diff --git a/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/override.ts.sample b/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/override.ts.sample index 9a5ebc4c991..bd398a12bdb 100644 --- a/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/override.ts.sample +++ b/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/override.ts.sample @@ -1,3 +1,5 @@ import { AmplifyDDBResourceTemplate } from '@aws-amplify/cli-extensibility-helper'; -export function override(resources: AmplifyDDBResourceTemplate) {} +export function override(resources: AmplifyDDBResourceTemplate) { + +} diff --git a/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/package.json b/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/package.json index 8ab0860ca75..34442b3019a 100644 --- a/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/package.json +++ b/packages/amplify-category-storage/resources/overrides-resource/DynamoDB/package.json @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@aws-amplify/cli-extensibility-helper": "1.0.1-ext15.0" + "@aws-amplify/cli-extensibility-helper": "latest" }, "devDependencies": { diff --git a/packages/amplify-category-storage/resources/overrides-resource/S3/override.ts.sample b/packages/amplify-category-storage/resources/overrides-resource/S3/override.ts.sample index 9f3a08a1b16..bdcb1521dd0 100644 --- a/packages/amplify-category-storage/resources/overrides-resource/S3/override.ts.sample +++ b/packages/amplify-category-storage/resources/overrides-resource/S3/override.ts.sample @@ -1,3 +1,5 @@ import { AmplifyS3ResourceTemplate } from '@aws-amplify/cli-extensibility-helper'; -export function override(resources: AmplifyS3ResourceTemplate) {} +export function override(resources: AmplifyS3ResourceTemplate) { + +} diff --git a/packages/amplify-category-storage/resources/overrides-resource/S3/package.json b/packages/amplify-category-storage/resources/overrides-resource/S3/package.json index bca40c7ea75..ccab2ab7b1e 100644 --- a/packages/amplify-category-storage/resources/overrides-resource/S3/package.json +++ b/packages/amplify-category-storage/resources/overrides-resource/S3/package.json @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@aws-amplify/cli-extensibility-helper": "1.0.1-ext15.0" + "@aws-amplify/cli-extensibility-helper": "latest" }, "devDependencies": { "typescript": "^4.2.4" diff --git a/packages/amplify-cli-extensibility-helper/src/index.ts b/packages/amplify-cli-extensibility-helper/src/index.ts index 29122f4335e..78f5106e190 100644 --- a/packages/amplify-cli-extensibility-helper/src/index.ts +++ b/packages/amplify-cli-extensibility-helper/src/index.ts @@ -3,5 +3,6 @@ export { AmplifyAuthCognitoStackTemplate, AmplifyUserPoolGroupStackTemplate } fr import { addCDKResourceDependency } from '@aws-amplify/amplify-category-custom'; export { AmplifyDDBResourceTemplate, AmplifyS3ResourceTemplate, AmplifyCDKL1 } from './types/storage/types'; import { getProjectInfo } from './helpers/project-info'; +import { AmplifyResourceProps } from '@aws-amplify/amplify-category-custom'; -export { getProjectInfo, addCDKResourceDependency }; +export { getProjectInfo, addCDKResourceDependency as addResourceDependency, AmplifyResourceProps }; diff --git a/packages/amplify-provider-awscloudformation/resources/overrides-resource/override.ts.sample b/packages/amplify-provider-awscloudformation/resources/overrides-resource/override.ts.sample index 019ac34c490..5f65af35290 100644 --- a/packages/amplify-provider-awscloudformation/resources/overrides-resource/override.ts.sample +++ b/packages/amplify-provider-awscloudformation/resources/overrides-resource/override.ts.sample @@ -1,3 +1,5 @@ import { AmplifyRootStackTemplate } from '@aws-amplify/cli-extensibility-helper'; -export function override(resources: AmplifyRootStackTemplate) {} +export function override(resources: AmplifyRootStackTemplate) { + +} diff --git a/packages/amplify-provider-awscloudformation/resources/overrides-resource/package.json b/packages/amplify-provider-awscloudformation/resources/overrides-resource/package.json index bca40c7ea75..ccab2ab7b1e 100644 --- a/packages/amplify-provider-awscloudformation/resources/overrides-resource/package.json +++ b/packages/amplify-provider-awscloudformation/resources/overrides-resource/package.json @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "@aws-amplify/cli-extensibility-helper": "1.0.1-ext15.0" + "@aws-amplify/cli-extensibility-helper": "latest" }, "devDependencies": { "typescript": "^4.2.4"