Skip to content

Commit

Permalink
chore(core): change helper functions to return response objects (#904)
Browse files Browse the repository at this point in the history
* Changed API functions to return response objects

* Fix remaining references to API helper functions

* One more reference to API Helper function

* CloudFront and lambda-sagemakerendpoint

* updated dynamodb

* Format errors

* Adjust Elasticsearch

* Includes S3, apigateway

* Missed Apigateway reference

* Upated fargate-helper

* One missed fargate reference

* One more fargate

* Fargate existing resource misses

* More fargate references

* missing whitespace

* all sns changes

* step functions

* sqs referencex

* Another sqs reference

* lambda-sqs-lambda

* one more

* nettlesome flummery

* Sagemaker Return values

* Clean up, ensure consistency

* Address Review Issues
  • Loading branch information
biffgaut committed Feb 20, 2023
1 parent dc48e48 commit de47a16
Show file tree
Hide file tree
Showing 123 changed files with 1,147 additions and 701 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class AlbToFargate extends Construct {
// CheckFargateProps confirms that the container is provided
this.container = props.existingContainerDefinitionObject!;
} else {
[this.service, this.container] = defaults.CreateFargateService(
const createFargateServiceResponse = defaults.CreateFargateService(
scope,
id,
this.vpc,
Expand All @@ -218,6 +218,8 @@ export class AlbToFargate extends Construct {
props.containerDefinitionProps,
props.fargateServiceProps
);
this.service = createFargateServiceResponse.service;
this.container = createFargateServiceResponse.containerDefinition;
}
// Add the Fargate Service to the
// to the ALB Listener we set up earlier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test('Test existing load balancer, vpc, service', () => {

const existingVpc = defaults.getTestVpc(stack);

const [testService, testContainer] = defaults.CreateFargateService(stack,
const createFargateServiceResponse = defaults.CreateFargateService(stack,
'test',
existingVpc,
undefined,
Expand All @@ -145,8 +145,8 @@ test('Test existing load balancer, vpc, service', () => {
const testProps: AlbToFargateProps = {
existingVpc,
publicApi: true,
existingFargateServiceObject: testService,
existingContainerDefinitionObject: testContainer,
existingFargateServiceObject: createFargateServiceResponse.service,
existingContainerDefinitionObject: createFargateServiceResponse.containerDefinition,
existingLoadBalancerObj: existingAlb,
listenerProps: {
protocol: 'HTTP'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const image = ecs.ContainerImage.fromRegistry('nginx');

const testExistingVpc = defaults.getTestVpc(stack);

const [testService, testContainer] = defaults.CreateFargateService(stack,
const createFargateServiceResponse = defaults.CreateFargateService(stack,
'test',
testExistingVpc,
undefined,
Expand All @@ -48,8 +48,8 @@ const existingAlb = new elb.ApplicationLoadBalancer(stack, 'test-alb', {
const testProps: AlbToFargateProps = {
existingVpc: testExistingVpc,
publicApi: true,
existingFargateServiceObject: testService,
existingContainerDefinitionObject: testContainer,
existingFargateServiceObject: createFargateServiceResponse.service,
existingContainerDefinitionObject: createFargateServiceResponse.containerDefinition,
existingLoadBalancerObj: existingAlb,
listenerProps: {
protocol: 'HTTP'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,18 @@ export class ApiGatewayToDynamoDB extends Construct {

// Since we are only invoking this function with an existing Table or tableProps,
// (not a table interface), we know that the implementation will always return
// a Table object and we can safely cast away the optional aspect of the type.
this.dynamoTable = defaults.buildDynamoDBTable(this, {
// a Table object and we can force assignment to the dynamoTable property.
const buildDynamoDBTableResponse = defaults.buildDynamoDBTable(this, {
existingTableObj: props.existingTableObj,
dynamoTableProps: props.dynamoTableProps
})[1] as dynamodb.Table;
});
this.dynamoTable = buildDynamoDBTableResponse.tableObject!;

// Setup the API Gateway
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] = defaults.GlobalRestApi(this,
props.apiGatewayProps, props.logGroupProps);
const globalRestApiResponse = defaults.GlobalRestApi(this, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = globalRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalRestApiResponse.role;
this.apiGatewayLogGroup = globalRestApiResponse.logGroup;

// Setup the API Gateway role
this.apiGatewayRole = new iam.Role(this, 'api-gateway-role', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ export class ApiGatewayToIot extends Construct {
}

// Setup the API Gateway
[this.apiGateway, this.apiGatewayCloudWatchRole,
this.apiGatewayLogGroup] = defaults.GlobalRestApi(this, extraApiGwProps, props.logGroupProps);
const globalRestApiResponse = defaults.GlobalRestApi(this, extraApiGwProps, props.logGroupProps);
this.apiGateway = globalRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalRestApiResponse.role;
this.apiGatewayLogGroup = globalRestApiResponse.logGroup;

// Validate the Query Params
const requestValidatorProps: api.RequestValidatorProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ export class ApiGatewayToKinesisStreams extends Construct {
});

// Setup the API Gateway
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] = defaults.GlobalRestApi(this,
props.apiGatewayProps, props.logGroupProps);
const globalRestApiResponse = defaults.GlobalRestApi(this, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = globalRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalRestApiResponse.role;
this.apiGatewayLogGroup = globalRestApiResponse.logGroup;

// Setup the API Gateway role
this.apiGatewayRole = new iam.Role(this, 'api-gateway-role', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class ApiGatewayToLambda extends Construct {
});

// Setup the API Gateway
[this.apiGateway, this.apiGatewayCloudWatchRole,
this.apiGatewayLogGroup] = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps, props.logGroupProps);
const globalRestApiResponse = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = globalRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalRestApiResponse.role;
this.apiGatewayLogGroup = globalRestApiResponse.group;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ export class ApiGatewayToSageMakerEndpoint extends Construct {
defaults.CheckProps(props);

// Setup the API Gateway
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] = defaults.GlobalRestApi(this,
props.apiGatewayProps, props.logGroupProps);
const globalRestApiResponse = defaults.GlobalRestApi(this, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = globalRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalRestApiResponse.role;
this.apiGatewayLogGroup = globalRestApiResponse.logGroup;

// Setup the API Gateway role
if (props.apiGatewayExecutionRole !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,21 @@ export class ApiGatewayToSqs extends Construct {
});

// Setup the queue
[this.sqsQueue] = defaults.buildQueue(this, 'queue', {
const buildQueueResponse = defaults.buildQueue(this, 'queue', {
existingQueueObj: props.existingQueueObj,
queueProps: props.queueProps,
deadLetterQueue: this.deadLetterQueue,
enableEncryptionWithCustomerManagedKey: props.enableEncryptionWithCustomerManagedKey,
encryptionKey: props.encryptionKey,
encryptionKeyProps: props.encryptionKeyProps
});
this.sqsQueue = buildQueueResponse.queue;

// Setup the API Gateway
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] = defaults.GlobalRestApi(this,
props.apiGatewayProps, props.logGroupProps);
const globalRestApiResponse = defaults.GlobalRestApi(this, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = globalRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalRestApiResponse.role;
this.apiGatewayLogGroup = globalRestApiResponse.logGroup;

// Setup the API Gateway role
this.apiGatewayRole = new iam.Role(this, 'api-gateway-role', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const app = new App();
const stack = new Stack(app, generateIntegStackName(__filename));
stack.templateOptions.description = 'Integration Test for aws-apigateway-sqs';

const [existingQueueObj] = buildQueue(stack, 'existing-queue', {});
const buildQueueResponse = buildQueue(stack, 'existing-queue', {});

new ApiGatewayToSqs(stack, 'test-api-gateway-sqs-existing-queue', {
existingQueueObj
existingQueueObj: buildQueueResponse.queue
});

// Synth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ export class CloudFrontToApiGatewayToLambda extends Construct {
lambdaFunctionProps: props.lambdaFunctionProps
});

[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] =
defaults.RegionalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps, props.logGroupProps);
const regionalLambdaRestApiResponse = defaults.RegionalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = regionalLambdaRestApiResponse.api;
this.apiGatewayCloudWatchRole = regionalLambdaRestApiResponse.role;
this.apiGatewayLogGroup = regionalLambdaRestApiResponse.group;

this.apiGateway.methods.forEach((apiMethod) => {
// Override the API Gateway Authorization Type from AWS_IAM to NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ export class CloudFrontToApiGateway extends Construct {

this.apiGateway = props.existingApiGatewayObj;

[this.cloudFrontWebDistribution, this.cloudFrontFunction, this.cloudFrontLoggingBucket] =
defaults.CloudFrontDistributionForApiGateway(
this,
props.existingApiGatewayObj,
props.cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.cloudFrontLoggingBucketProps,
props.responseHeadersPolicyProps
);
const cloudFrontDistributionForApiGatewayResponse = defaults.CloudFrontDistributionForApiGateway(
this,
props.existingApiGatewayObj,
props.cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.cloudFrontLoggingBucketProps,
props.responseHeadersPolicyProps
);
this.cloudFrontWebDistribution = cloudFrontDistributionForApiGatewayResponse.distribution;
this.cloudFrontFunction = cloudFrontDistributionForApiGatewayResponse.cloudfrontFunction;
this.cloudFrontLoggingBucket = cloudFrontDistributionForApiGatewayResponse.loggingBucket;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const inProps: lambda.FunctionProps = {

const func = defaults.deployLambdaFunction(stack, inProps);

const [_api] = defaults.RegionalLambdaRestApi(stack, func);
const regionalLambdaRestApiResponse = defaults.RegionalLambdaRestApi(stack, func);

_api.methods.forEach((apiMethod) => {
regionalLambdaRestApiResponse.api.methods.forEach((apiMethod) => {
// Override the API Gateway Authorization Type from AWS_IAM to NONE
const child = apiMethod.node.findChild('Resource') as api.CfnMethod;
if (child.authorizationType === 'AWS_IAM') {
Expand All @@ -52,7 +52,7 @@ _api.methods.forEach((apiMethod) => {
});

new CloudFrontToApiGateway(stack, 'cf-apigw', {
existingApiGatewayObj: _api,
existingApiGatewayObj: regionalLambdaRestApiResponse.api,
cloudFrontLoggingBucketProps: {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const inProps: lambda.FunctionProps = {

const func = defaults.deployLambdaFunction(stack, inProps);

const [_api] = defaults.RegionalLambdaRestApi(stack, func);
const regionalLambdaRestApiResponse = defaults.RegionalLambdaRestApi(stack, func);

_api.methods.forEach((apiMethod) => {
regionalLambdaRestApiResponse.api.methods.forEach((apiMethod) => {
// Override the API Gateway Authorization Type from AWS_IAM to NONE
const child = apiMethod.node.findChild('Resource') as api.CfnMethod;
if (child.authorizationType === 'AWS_IAM') {
Expand All @@ -51,7 +51,7 @@ _api.methods.forEach((apiMethod) => {
});

new CloudFrontToApiGateway(stack, 'test-cloudfront-apigateway', {
existingApiGatewayObj: _api,
existingApiGatewayObj: regionalLambdaRestApiResponse.api,
cloudFrontLoggingBucketProps: {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function deploy(stack: cdk.Stack) {

const func = defaults.deployLambdaFunction(stack, inProps);

const [api] = defaults.RegionalLambdaRestApi(stack, func);
const regionalLambdaRestApiResponse = defaults.RegionalLambdaRestApi(stack, func);

return new CloudFrontToApiGateway(stack, 'test-cloudfront-apigateway', {
existingApiGatewayObj: api
existingApiGatewayObj: regionalLambdaRestApiResponse.api
});
}

Expand Down Expand Up @@ -172,8 +172,8 @@ function createApi() {

const func = defaults.deployLambdaFunction(stack, inProps);

const [api] = defaults.RegionalLambdaRestApi(stack, func);
return {stack, api};
const regionalLambdaRestApiResponse = defaults.RegionalLambdaRestApi(stack, func);
return {stack, api: regionalLambdaRestApiResponse.api};
}

// --------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ export class CloudFrontToMediaStore extends Construct {
this.mediaStoreContainer = defaults.MediaStoreContainer(this, mediaStoreProps);
}

[this.cloudFrontWebDistribution, this.cloudFrontLoggingBucket, this.cloudFrontOriginRequestPolicy, this.cloudFrontFunction]
= defaults.CloudFrontDistributionForMediaStore(
this,
this.mediaStoreContainer,
cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.cloudFrontLoggingBucketProps,
props.responseHeadersPolicyProps
);
const DistributionResponse = defaults.CloudFrontDistributionForMediaStore(
this,
this.mediaStoreContainer,
cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.cloudFrontLoggingBucketProps,
props.responseHeadersPolicyProps
);
this.cloudFrontWebDistribution = DistributionResponse.distribution;
this.cloudFrontLoggingBucket = DistributionResponse.loggingBucket;
this.cloudFrontOriginRequestPolicy = DistributionResponse.requestPolicy;
this.cloudFrontFunction = DistributionResponse.cloudfrontFunction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,31 @@ export class CloudFrontToS3 extends Construct {
let bucket: s3.IBucket;

if (!props.existingBucketObj) {
[this.s3Bucket, this.s3LoggingBucket] = defaults.buildS3Bucket(this, {
const buildS3BucketResponse = defaults.buildS3Bucket(this, {
bucketProps: props.bucketProps,
loggingBucketProps: props.loggingBucketProps,
logS3AccessLogs: props.logS3AccessLogs
});
this.s3Bucket = buildS3BucketResponse.bucket;
bucket = this.s3Bucket;
} else {
bucket = props.existingBucketObj;
}

this.s3BucketInterface = bucket;

[this.cloudFrontWebDistribution, this.cloudFrontFunction, this.cloudFrontLoggingBucket] =
defaults.CloudFrontDistributionForS3(
this,
this.s3BucketInterface,
props.cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.originPath,
props.cloudFrontLoggingBucketProps,
props.responseHeadersPolicyProps
);
const cloudFrontDistributionForS3Response = defaults.CloudFrontDistributionForS3(
this,
this.s3BucketInterface,
props.cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.originPath,
props.cloudFrontLoggingBucketProps,
props.responseHeadersPolicyProps
);
this.cloudFrontWebDistribution = cloudFrontDistributionForS3Response.distribution;
this.cloudFrontFunction = cloudFrontDistributionForS3Response.cloudfrontFunction;
this.cloudFrontLoggingBucket = cloudFrontDistributionForS3Response.loggingBucket;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ export class CognitoToApiGatewayToLambda extends Construct {
existingLambdaObj: props.existingLambdaObj,
lambdaFunctionProps: props.lambdaFunctionProps
});
[this.apiGateway, this.apiGatewayCloudWatchRole, this.apiGatewayLogGroup] =
defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps, props.logGroupProps);
const globalLambdaRestApiResponse = defaults.GlobalLambdaRestApi(this, this.lambdaFunction, props.apiGatewayProps, props.logGroupProps);
this.apiGateway = globalLambdaRestApiResponse.api;
this.apiGatewayCloudWatchRole = globalLambdaRestApiResponse.role;
this.apiGatewayLogGroup = globalLambdaRestApiResponse.group;

this.userPool = defaults.buildUserPool(this, props.cognitoUserPoolProps);
this.userPoolClient = defaults.buildUserPoolClient(this, this.userPool, props.cognitoUserPoolClientProps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ export class DynamoDBStreamsToLambda extends Construct {
lambdaFunctionProps: props.lambdaFunctionProps
});

[this.dynamoTableInterface, this.dynamoTable] = defaults.buildDynamoDBTableWithStream(this, {
const buildDynamoDBTableWithStreamResponse = defaults.buildDynamoDBTableWithStream(this, {
dynamoTableProps: props.dynamoTableProps,
existingTableInterface: props.existingTableInterface
});
this.dynamoTableInterface = buildDynamoDBTableWithStreamResponse.tableInterface;
this.dynamoTable = buildDynamoDBTableWithStreamResponse.tableObject;

// Grant DynamoDB Stream read perimssion for lambda function
this.dynamoTableInterface.grantStreamRead(this.lambdaFunction.grantPrincipal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ export class EventbridgeToSns extends Construct {
}

// Setup the sns topic.
[this.snsTopic, this.encryptionKey] = defaults.buildTopic(this, {
const buildTopicResponse = defaults.buildTopic(this, {
existingTopicObj: props.existingTopicObj,
topicProps: props.topicProps,
enableEncryptionWithCustomerManagedKey: enableEncryptionParam,
encryptionKey: props.encryptionKey,
encryptionKeyProps: props.encryptionKeyProps
});

this.snsTopic = buildTopicResponse.topic;
this.encryptionKey = buildTopicResponse.key;
// Setup the event rule target as sns topic.
const topicEventTarget: events.IRuleTarget = {
bind: () => ({
Expand Down
Loading

0 comments on commit de47a16

Please sign in to comment.