【发布时间】:2021-11-03 23:44:07
【问题描述】:
我已经通过 cloudformation 创建了一个 EC2 实例,我正试图让它通过 cloudformation 直接在实例上安装 postgres。但是,当我通过 SSH 连接到我的实例并尝试通过命令行运行 psql 时,我不断收到:
bash: psql: command not found
我尝试过手动安装,使用以下命令安装 postgres,效果很好。
sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
可能是因为我只是在更新堆栈和 ec2 实例而不是创建一个新实例?
下面是来自 cloudformation 模板的 sn-p。当我更新模板时一切正常,但似乎仍未安装 postgres...
DbWrapper:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
postgresql: []
postgresql-server: []
postgresql-devel: []
postgresql-contrib: []
postgresql-docs: []
Properties:
ImageId: ami-f976839e #AMI aws linux 2
InstanceType: t2.micro
AvailabilityZone: eu-west-2a
SecurityGroupIds:
- !Ref Ec2SecurityGroup
SubnetId: !Ref SubnetA
KeyName: !Ref KeyPairName
UserData:
Fn::Base64:
!Join [ "", [
"#!/bin/bash -xe\n",
"sudo yum update\n",
"sudo yum install -y aws-cfn-bootstrap\n", #download aws helper scripts
"sudo /opt/aws/bin/cfn-init -v ", #use cfn-init to install packages in cloudformation init
!Sub "--stack ${AWS::StackName} ",
"--resource DbWrapper ",
"--configsets Install ",
!Sub "--region ${AWS::Region} ",
"\n" ] ]
【问题讨论】:
标签: bash postgresql amazon-web-services amazon-ec2 amazon-cloudformation