Skip to content

Commit

Permalink
Merge branch 'master' into add-vpc-arn
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 25, 2021
2 parents 936997c + 8d0c555 commit e85cac2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/cache-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ export interface CachePolicyProps {
* A Cache Policy configuration.
*
* @resource AWS::CloudFront::CachePolicy
* @link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html
*/
export class CachePolicy extends Resource implements ICachePolicy {

/**
* This policy is designed for use with an origin that is an AWS Amplify web app.
*/
public static readonly AMPLIFY = CachePolicy.fromManagedCachePolicy('2e54312d-136d-493c-8eb9-b001f22f67d2');
/**
* Optimize cache efficiency by minimizing the values that CloudFront includes in the cache key.
* Query strings and cookies are not included in the cache key, and only the normalized 'Accept-Encoding' header is included.
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/vpc-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ export interface VpcLookupOptions {
* @default aws-cdk:subnet-name
*/
readonly subnetGroupNameTag?: string;

/**
* Optional to override inferred region
*
* @default Current stack's environment region
*/
readonly region?: string;
}
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,15 @@ export class Vpc extends VpcBase {
filter.isDefault = options.isDefault ? 'true' : 'false';
}

const overrides: {[key: string]: string} = {};
if (options.region) {
overrides.region = options.region;
}

const attributes: cxapi.VpcContextResponse = ContextProvider.getValue(scope, {
provider: cxschema.ContextProvider.VPC_PROVIDER,
props: {
...overrides,
filter,
returnAsymmetricSubnets: true,
subnetGroupNameTag: options.subnetGroupNameTag,
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/vpc.from-lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ describe('vpc from lookup', () => {
restoreContextProvider(previous);

});
test('passes account and region', () => {
const previous = mockVpcContextProviderWith({
vpcId: 'vpc-1234',
subnetGroups: [],
}, options => {
expect(options.region).toEqual('region-1234');
});

const stack = new Stack();
const vpc = Vpc.fromLookup(stack, 'Vpc', {
vpcId: 'vpc-1234',
region: 'region-1234',
});

expect(vpc.vpcId).toEqual('vpc-1234');

restoreContextProvider(previous);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export class VpcEndpointServiceDomainName extends CoreConstruct {
// Track all domain names created, so someone doesn't accidentally associate two domains with a single service
private static readonly endpointServicesMap: { [endpointService: string]: string} = {};

/**
* The domain name associated with the private DNS configuration
*/
public domainName: string;

// The way this class works is by using three custom resources and a TxtRecord in conjunction
// The first custom resource tells the VPC endpoint service to use the given DNS name
// The VPC endpoint service will then say:
Expand All @@ -58,16 +63,16 @@ export class VpcEndpointServiceDomainName extends CoreConstruct {

const serviceUniqueId = Names.nodeUniqueId(props.endpointService.node);
const serviceId = props.endpointService.vpcEndpointServiceId;
const privateDnsName = props.domainName;
this.domainName = props.domainName;

// Make sure a user doesn't accidentally add multiple domains
this.validateProps(props);

VpcEndpointServiceDomainName.endpointServicesMap[serviceUniqueId] = privateDnsName;
VpcEndpointServiceDomainName.endpointServicesMap[serviceUniqueId] = this.domainName;
VpcEndpointServiceDomainName.endpointServices.push(props.endpointService);

// Enable Private DNS on the endpoint service and retrieve the AWS-generated configuration
const privateDnsConfiguration = this.getPrivateDnsConfiguration(serviceUniqueId, serviceId, privateDnsName);
const privateDnsConfiguration = this.getPrivateDnsConfiguration(serviceUniqueId, serviceId, this.domainName);

// Tell AWS to verify that this account owns the domain attached to the service
this.verifyPrivateDnsConfiguration(privateDnsConfiguration, props.publicHostedZone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,20 @@ test('throws if creating multiple domains for a single service', () => {
publicHostedZone: zone,
});
}).toThrow(/Cannot create a VpcEndpointServiceDomainName for service/);
});


test('endpoint domain name property equals input domain name', () => {
// GIVEN
vpces = new VpcEndpointService(stack, 'NameTest', {
vpcEndpointServiceLoadBalancers: [nlb],
});

const dn = new VpcEndpointServiceDomainName(stack, 'EndpointDomain', {
endpointService: vpces,
domainName: 'name-test.aws-cdk.dev',
publicHostedZone: zone,
});
expect(dn.domainName).toEqual('name-test.aws-cdk.dev');

});

0 comments on commit e85cac2

Please sign in to comment.