Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-lambda-opensearch): created new construct #818

Merged
merged 9 commits into from
Oct 11, 2022

Conversation

mickychetta
Copy link
Contributor

@mickychetta mickychetta commented Sep 29, 2022

Issue #817 , if available:

Description of changes:

  • Created new construct aws-lambda-opensearch
  • Added OpenSearch helper and default files
  • Added unit and integ tests for construct

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

fixes #817

@mickychetta mickychetta self-assigned this Sep 29, 2022
@biffgaut biffgaut changed the title feat(aws-lambda-opensearch): Created README feat(aws-lambda-opensearch): Created new construct Sep 29, 2022
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 8097acd
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: e60d4fb
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 620a2ee
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are 2 comments requiring changes - one about the service role and one about the comment on Cognito Domain name.

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: fcbfc34
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

biffgaut
biffgaut previously approved these changes Sep 30, 2022
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 1d01293
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: d926fd2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository


/**
* @summary Constructs a new instance of the LambdaToOpenSearch class.
* @param {cdk.App} scope - represents the scope for all the resources.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is just copied from other Constructs, but can you think of a reason this says cdk.App instead of Construct? The type below is clearly Construct...
Should we change this in every construct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should change this in every construct

@@ -120,3 +120,18 @@ export function setupCognitoForElasticSearch(scope: Construct, domainName: strin

return cognitoAuthorizedRole;
}

export function setupOpenSearchCognito(scope: Construct, domainName: string):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you didn't follow the same naming pattern as setupCognitoForElasticSearch?

It's fine if you have a reason, the ElasticSearch stuff will probably not live forever, but if we're changing the naming pattern we should have a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, changed to setupCognitoForOpenSearch

var creds = new AWS.EnvironmentCredentials('AWS');
var endpoint = new AWS.Endpoint(openSearchDomain.endpoint);

function postDocumentToOpenSearch(doc, context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you launched this and confirm that data ends up in OpenSearch when run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, data is shown in dashboards


const MAXIMUM_AZS_IN_OPENSEARCH_DOMAIN = 3;

export interface BuildOpenSearchProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait a minute - if this exists, why were the props defined as any in index.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BuildOpenSearchProps interface are readonly, we want to to add securityGroupIds if a VPC is present

// ClusterStatus.red maximum is >= 1 for 1 minute, 1 consecutive time
alarms.push(new cloudwatch.Alarm(scope, 'StatusRedAlarm', {
metric: new cloudwatch.Metric({
namespace: 'AWS/ES',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why still ES instead of OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSearch kept ES prefix instead of creating new OS

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: cdfc289
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@biffgaut biffgaut changed the title feat(aws-lambda-opensearch): Created new construct feat(aws-lambda-opensearch): created new construct Oct 10, 2022
Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change requested

Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments, one question

handler: 'index.handler'
};

const openSearchDomain = 'solutions-constructs-domain';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we don't specify a cognito domain like we do in the Elasticsearch version of this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the integ.no-arguments.ts for aws-lambda-opensearch, I used only the required arguments to deploy the stack. Specifying both OpenSearch and Cognito domain separately is handled in integ.domain-arguments.ts.

return new LambdaToOpenSearch(stack, 'test-lambda-opensearch-stack', props);
}

function getDefaultTestLambdaProps(): lambda.FunctionProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to change this, but it could have been a constant to reduce complexity a little (most compile languages would probably make this optimization at compile time):

const defaultTestLambdaProps: lambda.FunctionProps = {
    code: lambda.Code.fromAsset(`${__dirname}/lambda`),
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'index.handler',
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using this approach, I get an Asset resource already exists in another stack:
Asset is already associated with another stack 'Default'. Create a new Code instance for every stack.

Using a function will create a unique reference id for the Code/Asset resource in each CloudFormation stack:
When the AWS CDK deploys an app that references assets (either directly by the app code or through a library), the AWS CDK CLI first prepares and publishes the assets to an Amazon S3 bucket or Amazon ECR repository, which was created during bootstrapping. Only then are the resources defined in the stack deployed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - thanks, I learned something there!

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 64df182
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with 1 comment

return new LambdaToOpenSearch(stack, 'test-lambda-opensearch-stack', props);
}

function getDefaultTestLambdaProps(): lambda.FunctionProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - thanks, I learned something there!

@biffgaut biffgaut merged commit f31f59d into awslabs:main Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Pattern: aws-lambda-opensearch
3 participants