forked from aws-amplify/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: populate custom resources CDK stacks with region and account (aw…
- Loading branch information
Showing
4 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/amplify-category-custom/src/__tests__/utils/generate-cfn-from-cdk.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getCDKProps } from '../../utils/generate-cfn-from-cdk'; | ||
|
||
describe('generate-cfn-from-cdk', () => { | ||
describe('getCDKProps', () => { | ||
beforeEach(() => { | ||
process.env = {}; | ||
}); | ||
|
||
test('should return undefined if CDK env vars are not set', () => { | ||
const actual = getCDKProps(); | ||
expect(actual).toBeUndefined(); | ||
}); | ||
|
||
test('should return cdk props with env set', () => { | ||
process.env = { | ||
CDK_DEFAULT_ACCOUNT: 'some_account_id', | ||
CDK_DEFAULT_REGION: 'us-east-1', | ||
}; | ||
|
||
const actual = getCDKProps(); | ||
|
||
expect(actual.env?.account).toEqual('some_account_id'); | ||
expect(actual.env?.region).toEqual('us-east-1'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/amplify-e2e-tests/custom-resources/barebone-cdk-stack.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as sqs from 'aws-cdk-lib/aws-sqs'; | ||
import * as sns from 'aws-cdk-lib/aws-sns'; | ||
import * as subs from 'aws-cdk-lib/aws-sns-subscriptions'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import { Construct } from 'constructs'; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper'; | ||
|
||
export class cdkStack extends cdk.Stack { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
constructor(scope: 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 parameter */ | ||
new cdk.CfnParameter(this, 'env', { | ||
type: 'String', | ||
description: 'Current Amplify CLI env name', | ||
}); | ||
/* AWS CDK code goes here - learn more: https://docs.aws.amazon.com/cdk/latest/guide/home.html */ | ||
|
||
ec2.Vpc.fromLookup(this, 'VPC', { | ||
isDefault: true, | ||
}); | ||
|
||
const queue = new sqs.Queue(this, 'sqs-queue'); | ||
// 👇 create sns topic | ||
const topic = new sns.Topic(this, 'sns-topic'); | ||
|
||
// 👇 subscribe queue to topic | ||
topic.addSubscription(new subs.SqsSubscription(queue)); | ||
|
||
// creation of resources inside the VPC | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters