-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apprunner): VpcConnector construct
- Loading branch information
Showing
28 changed files
with
2,091 additions
and
27 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// AWS::AppRunner CloudFormation Resources: | ||
export * from './apprunner.generated'; | ||
export * from './service'; | ||
export * from './vpc-connector'; |
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
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,135 @@ | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { CfnVpcConnector } from './apprunner.generated'; | ||
|
||
/** | ||
* Properties of the AppRunner VPC Connector | ||
*/ | ||
export interface VpcConnectorProps { | ||
/** | ||
* A list of IDs of security groups that App Runner should use for access to AWS resources under the specified subnets. | ||
* | ||
* @default - the default security group of the VPC which allows all outbound traffic. | ||
*/ | ||
readonly securityGroups?: ec2.ISecurityGroup[]; | ||
|
||
/** | ||
* A list of subnets that App Runner should use when it associates the service with a custom Amazon VPC. | ||
*/ | ||
readonly subnets: ec2.ISubnet[]; | ||
|
||
/** | ||
* The name for the VpcConnector. | ||
* | ||
* @default - a name generated by CloudFormation | ||
*/ | ||
readonly vpcConnectorName?: string; | ||
} | ||
|
||
/** | ||
* Attributes for the App Runner VPC Connector | ||
*/ | ||
export interface VpcConnectorAttributes { | ||
/** | ||
* The name of the VPC connector. | ||
*/ | ||
readonly vpcConnectorName: string; | ||
|
||
/** | ||
* The ARN of the VPC connector. | ||
*/ | ||
readonly vpcConnectorArn: string; | ||
|
||
/** | ||
* The revision of the VPC connector. | ||
*/ | ||
readonly vpcConnectorRevision: number; | ||
} | ||
|
||
/** | ||
* Represents the App Runner VPC Connector. | ||
*/ | ||
export interface IVpcConnector extends cdk.IResource { | ||
/** | ||
* The Name of the VPC connector. | ||
*/ | ||
readonly vpcConnectorName: string; | ||
|
||
/** | ||
* The ARN of the VPC connector. | ||
*/ | ||
readonly vpcConnectorArn: string; | ||
} | ||
|
||
/** | ||
* The App Runner VPC Connector | ||
*/ | ||
export class VpcConnector extends cdk.Resource { | ||
/** | ||
* Import from VPC connector name. | ||
*/ | ||
public static fromVpcConnectorName(scope: Construct, id: string, vpcConnectorName: string): IVpcConnector { | ||
class Import extends cdk.Resource { | ||
public vpcConnectorName = vpcConnectorName; | ||
public vpcConnectorArn = cdk.Stack.of(this).formatArn({ | ||
resource: 'vpcconnector', | ||
service: 'apprunner', | ||
resourceName: vpcConnectorName, | ||
}) | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* Import from VPC connector attributes. | ||
*/ | ||
public static fromServiceAttributes(scope: Construct, id: string, attrs: VpcConnectorAttributes): IVpcConnector { | ||
const vpcConnectorArn = attrs.vpcConnectorArn; | ||
const vpcConnectorName = attrs.vpcConnectorName; | ||
const vpcConnectorRevision = attrs.vpcConnectorRevision; | ||
|
||
class Import extends cdk.Resource { | ||
public readonly vpcConnectorArn = vpcConnectorArn | ||
public readonly vpcConnectorName = vpcConnectorName | ||
public readonly vpcConnectorRevision = vpcConnectorRevision | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
private readonly props: VpcConnectorProps; | ||
|
||
/** | ||
* The ARN of the VPC connector. | ||
* @attribute | ||
*/ | ||
readonly vpcConnectorArn: string; | ||
|
||
/** | ||
* The revision of the VPC connector. | ||
* @attribute | ||
*/ | ||
readonly vpcConnectorRevision: number; | ||
|
||
/** | ||
* The name of the VPC connector. | ||
* @attribute | ||
*/ | ||
readonly vpcConnectorName: string; | ||
|
||
public constructor(scope: Construct, id: string, props: VpcConnectorProps) { | ||
super(scope, id); | ||
|
||
this.props = props; | ||
|
||
const resource = new CfnVpcConnector(this, 'VpcConnector', { | ||
subnets: this.props.subnets.map(subnet => subnet.subnetId), | ||
securityGroups: this.props.securityGroups?.map(securityGroup => securityGroup.securityGroupId), | ||
vpcConnectorName: this.props.vpcConnectorName, | ||
}); | ||
|
||
this.vpcConnectorArn = resource.attrVpcConnectorArn; | ||
this.vpcConnectorRevision = resource.attrVpcConnectorRevision; | ||
this.vpcConnectorName = resource.ref; | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
packages/@aws-cdk/aws-apprunner/test/integ.service-vpc-connector.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,49 @@ | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Service, Source, VpcConnector } from '../lib'; | ||
|
||
|
||
const app = new cdk.App(); | ||
|
||
const stack = new cdk.Stack(app, 'integ-apprunner'); | ||
|
||
// Scenario 6: Create the service from ECR public with a VPC Connector | ||
const vpc = new ec2.Vpc(stack, 'Vpc', { | ||
cidr: '10.0.0.0/16', | ||
}); | ||
|
||
const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup', { vpc }); | ||
|
||
const vpcConnector = new VpcConnector(stack, 'VpcConnector', { | ||
subnets: vpc.publicSubnets, | ||
securityGroups: [securityGroup], | ||
vpcConnectorName: 'MyVpcConnector', | ||
}); | ||
|
||
const service6 = new Service(stack, 'Service6', { | ||
source: Source.fromEcrPublic({ | ||
imageConfiguration: { | ||
port: 8000, | ||
}, | ||
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', | ||
}), | ||
vpcConnector, | ||
}); | ||
new cdk.CfnOutput(stack, 'URL6', { value: `https://${service6.serviceUrl}` }); | ||
|
||
// Scenario 7: Create the service from ECR public and associate it with an existing VPC Connector | ||
|
||
const service7 = new Service(stack, 'Service7', { | ||
source: Source.fromEcrPublic({ | ||
imageConfiguration: { | ||
port: 8000, | ||
}, | ||
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', | ||
}), | ||
vpcConnector: VpcConnector.fromServiceAttributes(stack, 'ImportedVpcConnector', { | ||
vpcConnectorArn: vpcConnector.vpcConnectorArn, | ||
vpcConnectorName: vpcConnector.vpcConnectorName, | ||
vpcConnectorRevision: vpcConnector.vpcConnectorRevision, | ||
}), | ||
}); | ||
new cdk.CfnOutput(stack, 'URL7', { value: `https://${service7.serviceUrl}` }); |
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-apprunner/test/service-ecr-public.integ.snapshot/cdk.out
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"17.0.0"} | ||
{"version":"19.0.0"} |
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
4 changes: 2 additions & 2 deletions
4
packages/@aws-cdk/aws-apprunner/test/service-ecr-public.integ.snapshot/integ.json
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
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-apprunner/test/service-ecr-public.integ.snapshot/manifest.json
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "17.0.0", | ||
"version": "19.0.0", | ||
"artifacts": { | ||
"Tree": { | ||
"type": "cdk:tree", | ||
|
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
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-apprunner/test/service-ecr.integ.snapshot/cdk.out
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"17.0.0"} | ||
{"version":"19.0.0"} |
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
4 changes: 2 additions & 2 deletions
4
packages/@aws-cdk/aws-apprunner/test/service-ecr.integ.snapshot/integ.json
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
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-apprunner/test/service-ecr.integ.snapshot/manifest.json
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "17.0.0", | ||
"version": "19.0.0", | ||
"artifacts": { | ||
"Tree": { | ||
"type": "cdk:tree", | ||
|
Oops, something went wrong.