AWS Elasticache Redis群集配置

发布于 2025-02-11 22:18:57 字数 1620 浏览 2 评论 0原文

我对Terraform有点陌生,并且需要在此问题上有一些帮助。它创建了根据资源,但是在连接到端点时,我会暂停。我注意到实际上并未创建安全组,但我不确定为什么。任何帮助将不胜感激。

配置:

provider "aws" {
  region = "us-west-2"
}

resource "aws_elasticache_cluster" "example" {
  cluster_id           = "cluster-example"
  engine               = "redis"
  node_type            = "cache.m4.large"
  num_cache_nodes      = 1
  parameter_group_name = "default.redis3.2"
  engine_version       = "3.2.10"
  port                 = 6379
}

resource "aws_security_group" "example" {
  name        = "example"
  description = "Used by the example Redis cluster"
  vpc_id      = "${aws_vpc.example.id}"

  ingress {
    description      = "TLS from VPC"
    from_port        = 443
    to_port          = 443
    protocol         = "tcp"
    cidr_blocks      = [aws_vpc.example.cidr_block]
  }

  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
    ipv6_cidr_blocks = ["::/0"]
  }
}

resource "aws_vpc" "example" {
  cidr_block = "10.0.0.0/16"

  tags = {
    Name = "example"
  }
}

resource "aws_subnet" "example" {
  vpc_id     = "${aws_vpc.example.id}"
  cidr_block = "10.0.0.0/20"

  tags = {
    Name = "example"
  }
}

resource "aws_elasticache_subnet_group" "example" {
  name        = "example"
  description = "Example subnet group"
  subnet_ids  = ["${aws_subnet.example.id}"]
}

连接到端点:(

import os
import redis

ENDPOINT = os.environ.get('REDIS_HOST')

client = redis.Redis(host=ENDPOINT, port=6379, db=0)

client.ping()

无密码群集)

编辑: 我在本地机器上打电话给Python的端点。

I'm a bit new to terraform and was and needed some help on what's the issue with this. It creates the according resources but when connecting to the endpoint, I get a timeout. I noticed the security group isn't actually being created but I'm not sure why. Any help would be appreciated.

configuration:

provider "aws" {
  region = "us-west-2"
}

resource "aws_elasticache_cluster" "example" {
  cluster_id           = "cluster-example"
  engine               = "redis"
  node_type            = "cache.m4.large"
  num_cache_nodes      = 1
  parameter_group_name = "default.redis3.2"
  engine_version       = "3.2.10"
  port                 = 6379
}

resource "aws_security_group" "example" {
  name        = "example"
  description = "Used by the example Redis cluster"
  vpc_id      = "${aws_vpc.example.id}"

  ingress {
    description      = "TLS from VPC"
    from_port        = 443
    to_port          = 443
    protocol         = "tcp"
    cidr_blocks      = [aws_vpc.example.cidr_block]
  }

  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
    ipv6_cidr_blocks = ["::/0"]
  }
}

resource "aws_vpc" "example" {
  cidr_block = "10.0.0.0/16"

  tags = {
    Name = "example"
  }
}

resource "aws_subnet" "example" {
  vpc_id     = "${aws_vpc.example.id}"
  cidr_block = "10.0.0.0/20"

  tags = {
    Name = "example"
  }
}

resource "aws_elasticache_subnet_group" "example" {
  name        = "example"
  description = "Example subnet group"
  subnet_ids  = ["${aws_subnet.example.id}"]
}

connection to endpoint:

import os
import redis

ENDPOINT = os.environ.get('REDIS_HOST')

client = redis.Redis(host=ENDPOINT, port=6379, db=0)

client.ping()

(passwordless cluster)

EDIT:
I call the endpoint in python on my local machine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵性 2025-02-18 22:18:57

您无法直接从AWS外部访问EC群集,因为它可以仅从VPC访问。如果要从家庭网络连接,则必须使用VPN,Direct Connect或SSH隧道。

You can't access EC cluster from outside of AWS directly, as it can only be accessed from VPC. You must use VPN, Direct Connect or SSH tunnel if you want to connect from your home network.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文