Giter Club home page Giter Club logo

opensearch-vpc-cdk's Introduction

OpenSearch in VPC with CDK

Overview

This is a sample implementation for Amazon OpenSearch Service deployed in VPC with CDK (TypeScript). In this sample, all resources are deployed in private subnet, and end users have access to the OpenSearch Dashboards via port forwading in AWS Session Manager, avoiding need for exposing SSH port to the internet. This sample also contains indexing data into OpenSearch from AWS Lambda deployed in VPC.

opensearch-vpc-cdk

Pre-requisites

  • Configuration of AWS profile
  • Node.js (Active LTS version preferred)
  • Docker
    • Docker is used to create packages for Lambda function.
  • Session Manager Plugin
    • Session Manager Plugin is required for access to OpenSearch Dashboards using Session Manager.

Getting started

1. Deployment

Run the following commands to deploy the sample in this directory.

npm ci
npx cdk bootstrap
npx cdk deploy

Initial deployment usually takes about 20 to 30 minutes. You can also use npx cdk deploy command to modify deployed resources. If the deployment completes successfully, you will get outputs like below. Outputs values will be used in the following steps.

 ✅  OpensearchVpcCdkStack

✨  Deployment time: 1521.61s

Outputs:
OpensearchVpcCdkStack.BastionHostBastionHostIdC743CBD6 = i-xxxxxxxx
OpensearchVpcCdkStack.IndexingFunctionName = OpensearchVpcCdkStack-DataIndexxxxxxx
OpensearchVpcCdkStack.OpenSearchDomainHost = vpc-domainxxxxxxxxxx.ap-northeast-1.es.amazonaws.com
Stack ARN:
arn:aws:cloudformation:ap-northeast-1:123456789012:stack/OpensearchVpcCdkStack/078d0be0-e3c5-11ed-8d9c-0a455fdf670f

✨  Total time: 1543.55s

2. (Optional) Indexing sample data

You can run this lambda to index sample data to OpenSearch. If you just want to access OpenSearch Dashboards, you do not need to do this step. Execute the following command after replacing the <IndexingFunctionName> to the above output value.

aws lambda invoke --function-name <IndexingFunctionName> --cli-binary-format raw-in-base64-out --payload '{ "productId": "product_123", "price": 200 }' /dev/stdout

3. Accessing OpenSearch Dashboards

Run the following command to access OpenSearch Dashboards, after replacing <BastionHostId> and <OpenSearchDomainHost> to the values output by cdk.

aws ssm start-session --target <BastionHostId> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"portNumber":["443"],"localPortNumber":["8157"], "host":["<OpenSearchDomainHost>"]}'

After starting session, access https://localhost:8157/_dashboards in your browser. Warning may appear because the domain (*.<region>.es.amazonaws.com) in the certificate is different from the domain (localhost) you access. Since this does not cause serious problems, continue accessing the site, and you will see OpenSearch Dashboards like below.

opensearch-dashboards

opensearch-vpc-cdk's People

Contributors

gteu avatar amazon-auto avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.