首页 > 解决方案 > bash:./create.sh:权限被拒绝,尝试构建堆栈时

问题描述

我已经创建了一个具有 AdministratorAccess 策略的用户,我可以运行aws s3 ls并且它运行良好,但是当我尝试在 bash 中使用模板来使用 Cloudformation 构建堆栈时

aws cloudformation create-stack \
--stack-name $1 \
--template-body file://$2 \
--region=us-west-2 \
--capabilities CAPABILITY_IAM

如果我尝试在包含所有文件的目录中构建一个堆栈./create.sh test testVPC.yml,我得到一个错误:bash: ./create.sh: Permission denied

我正在尝试部署一个简单的 VPC:

Description: >
  This template deploys a VCP.
Resources:
  VPC:
  Type: AWS::EC2::VPC
  Properties:
  CidrBlock: 10.0.0.0/24
  EnableDnsHostnames: true

请你帮助我好吗?

标签: bashamazon-web-servicesamazon-cloudformation

解决方案


您的错误似乎是 bash 错误,而不是 CloudFormation 错误。为了运行./create.sh,你所在的 linux/unix 系统必须相信 create.sh 是一个可执行程序。

chmod 755 create.sh

此外,通常 create.sh 的第一行应指示使用哪种语言解释器,在您的情况下为 bash:

#!/bin/bash

尽管这可能看起来是可选的,因为在某些系统上,如果#!省略第一行,它仍然使用 sh(或 bash)。


推荐阅读