标签: aws-cloudformation

删除 CFN 堆栈时无法删除非空 S3 存储桶和日志组

当我删除 cloudformation 堆栈时,它不会删除其中的非空 s3 存储桶和非空日志组。

知道为什么会这样吗?我怎样才能覆盖删除它?

amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
2042
查看次数

AWS GovClouds 的云形成模板中的 ARN 结构

我在 AWS 上为不同区域提供了产品。但对于 GovCloud 区域,ARN 结构与普通区域不同。当我们使用 ARN 时,政府区域中的正常部署失败。为此,我添加了一个检查区域名称是否为 Gov 区域的检查。但我必须对区域名称进行硬编码。是否有任何通用条件来检查当前区域是 CFT 中的政府区域?

amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
3977
查看次数

cloudformation Sub 函数中的“|-”是什么意思?

考虑示例(来源

  # State machine for testing Athena Runner
  AthenaRunnerTestETLOrchestrator:
    Type: "AWS::StepFunctions::StateMachine"
    Properties:
      StateMachineName: AthenaRunnerTestETLOrchestrator
      DefinitionString:
        Fn::Sub:
          - |-
            {
              "StartAt": "Configure Athena Query",
              "States": {
                "Configure Athena Query":{
                  "Type": "Pass",
                  "Result": "{ \"AthenaQueryString\" : \"SELECT * FROM ${GlueTableName} limit 10;\", \"AthenaDatabase\": \"${GlueDatabaseName}\", \"AthenaResultOutputLocation\": \"${AthenaResultOutputLocation}\", \"AthenaResultEncryptionOption\": \"${AthenaResultEncryptionOption}\"}",
                  "Next": "Execute Athena Query"
                },
                "Execute Athena Query":{
                  "Type": "Task",
                  "Resource": "${AthenaRunnerActivityArn}",
                  "End": true
                }
              }
            }
          - {
            GlueDatabaseName: !Ref MarketingAndSalesDatabaseName,
            GlueTableName: !Ref MarketingTableName,
            AthenaRunnerActivityArn: !Ref AthenaRunnerActivity,
            AthenaResultOutputLocation: !Sub "s3://${SourceDataBucketName}/athena-runner-output/",
            AthenaResultEncryptionOption: …
Run Code Online (Sandbox Code Playgroud)

yaml amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
2821
查看次数

AWS Config - MaxNumberOfDeliveryChannelsExceededException

我需要一些建议,我想创建一个例外,该例外将忽略 AWS Config Delivery 通道(如果已经创建)。目前我收到以下错误 -

无法放置传递通道“Security-DeliveryChannel-V156D0TVGUC6”,因为已达到传递通道的最大数量:1。(服务:AmazonConfig;状态代码:400;错误代码:MaxNumberOfDeliveryChannelsExceededException;

我已经编写了以下代码,并且需要一些帮助来编写一些异常,以便在 AWS Config - 交付通道 - 已创建的情况下忽略以下资源创建

DeliveryChannel:
Type: 'AWS::Config::DeliveryChannel'
Properties:
ConfigSnapshotDeliveryProperties:
DeliveryFrequency: !Ref DeliveryFrequency
S3BucketName: !If [InternalBucket, !Ref AuditLogBucket, !Ref ExternalAuditLogBucket]
SnsTopicARN: !Ref AuditLogSNSTopic
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
2565
查看次数

如何获取 AWS KMS Key Arn 并通过 CloudFormation 将其传递到 IAM 角色内联策略中?

我正在尝试通过 CloudFormation 模板创建 IAM 角色和 KMS 密钥。我的要求是首先我需要创建 KMS 密钥,获取它的 ARN,然后在创建 IAM 角色时,必须传递该 KMS ARN。我的政策是这样的:

Resources:
  myKey:
    Type: AWS::KMS::Key
    Properties:
      Description: Key for encrypting S3 Buckets
      Enabled: TRUE
      KeyPolicy:
        Version: '2012-10-17'
        Statement:
          - Sid: Enable IAM User Permissions
            Effect: Allow
            Principal:
              AWS: arn:aws:iam::11111111:root
            Action: kms:*
            Resource: '*'
      KeyUsage:  ENCRYPT_DECRYPT
  myAlias:
    Type: AWS::KMS::Alias
    Properties:
      AliasName: alias/key_for_s3_encrytpion
      TargetKeyId:
        Ref: myKey
  RootRole:
      Type: 'AWS::IAM::Role'
      Properties:
        RoleName: 'Lambda-S3-SNS-VPC-Role-cft'
        AssumeRolePolicyDocument:
          Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
              Action:
                - 'sts:AssumeRole'
        Path: /
        ManagedPolicyArns: …
Run Code Online (Sandbox Code Playgroud)

aws-cloudformation amazon-iam amazon-kms

1
推荐指数
1
解决办法
3746
查看次数

如何按标签值过滤 CloudFormation 堆栈?

我想获取具有以下标记/值的所有 CloudFormation 堆栈的堆栈名称:

elasticbeanstalk:environment-namemyenvironment

有什么办法可以做到这一点吗?我尝试了这个查询,但它引发了语法错误:

aws cloudformation describe-stacks --query 'Stacks[].Tags[?Key == `elasticbeanstalk:environment-name` && ?Value == `myenvironment`]'
Run Code Online (Sandbox Code Playgroud)

编辑

我弄清楚了过滤部分,但我不知道如何获取堆栈名称。这将返回 null,如何检索 StackName?

aws cloudformation describe-stacks --query 'Stacks[].Tags[?Key == `elasticbeanstalk:environment-name` && Value == `myenv`].{MyStack: StackName}'
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation aws-cli jmespath

1
推荐指数
1
解决办法
2843
查看次数

允许从 Amazon EC2 实例到 Amazon S3 存储桶的跨账户访问

我在帐户 B 中有 S3 存储桶“跨存储桶”。现在我希望帐户 A 中存在的 EC2 访问帐户 B 中的此存储桶“跨存储桶”。

我需要使用 IAM 角色来实现此目的,因为我们不允许创建用户。

我已使用以下模板在帐户 B 中创建角色

 AWSTemplateFormatVersion : '2010-09-09'
 Description: 'Cross account role for S3'

 Parameters:
   AccountId:
   Type: String
   Description: Account ID of admin account (containing user to allow)

 Resources:
 CrossAccountRole:
Type: AWS::IAM::Role
Properties:
  AssumeRolePolicyDocument:
    Statement:
      - Effect: Allow
        Action: sts:AssumeRole
        Principal:
          AWS:
            - !Sub arn:aws:iam::${AccountId}:root
  Path: /
  Policies:
    - PolicyName: my-s3-delegate
      PolicyDocument:
        Statement:
          - Effect: Allow
            Action:
              - s3:ListBucket
              - s3:GetObject
            Resource: "*"
  RootInstanceProfile: 
Type: "AWS::IAM::InstanceProfile"
Properties: 
  Path: …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services aws-cloudformation amazon-iam

1
推荐指数
1
解决办法
4929
查看次数

AWS CFN 错误“参数 groupName 不能与参数子网一起使用”

使用以下 yaml 时出现错误。我检查了代码,但我不认为有任何问题。我的结构计划有一个带有 2 个公有子网和 2 个私有子网的 VPC。一个Web服务器实例将放置在公共子网2中。我认为该问题可能与实例创建有关,因为该错误是在实例创建过程中出现的。

Parameters:
  EnvironmentName:
    Description: An environment name that is prefixed to resource names
    Type: String

  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
    Type: AWS::EC2::KeyPair::KeyName
    ConstraintDescription: must be the name of an existing EC2 KeyPair.

  SSHLocation:
    Description: The IP address range that can be used to SSH to the EC2 instances
    Type: String
    MinLength: '9'
    MaxLength: '18'
    Default: 0.0.0.0/0
    AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
    ConstraintDescription: must be a valid …
Run Code Online (Sandbox Code Playgroud)

yaml amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
2839
查看次数

AWS Cloudformation SAM 文件 - 如何拆分为许多较小的文件?

我正在创建定义我们的产品环境的模板。在我们的系统中,我们将使用许多 Lambda,它会生成巨大的 Cloudformation 模板文件,其中包含许多(甚至是大量的)条目,如下所示。可以将一个模板文件拆分为多个单独的文件(例如,一个文件用于一项功能,或者至少一个文件用于一项服务)。我知道有子堆栈机制,但在子堆栈中我无法将函数定义存储在本地文件中(我只能给出模板 URL),并且我不确定是否可以将参数传递给子堆栈。正如下面的示例所示,有许多参数和对其他资源的引用。

  APILambadFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ../lambda_functions/
      Handler: getUserInfo.lambda_handler
      FunctionName: !Sub ${CreatorUsername}-getUserInfo
      Runtime: python3.7
      VpcConfig:
        SecurityGroupIds:
          - !Ref SecurityGroupLamda
        SubnetIds:
          - !Ref PrivateSubnet1
          - !Ref PrivateSubnet2
      Role:
        Fn::GetAtt: [ RoleLamdaRestAPI, Arn ]   # Rola dla wszystkich Lamd restowych
      Environment:
        Variables:
          DB_HOST: !GetAtt 'PostgresDB.Endpoint.Address'
          DB_PORT: !GetAtt 'PostgresDB.Endpoint.Port'
          DB_NAME: !Sub '{{resolve:ssm:/${CreatorUsername}/${EnvType}/PostgresSQL/DBName:1}}'
          DB_USERNAME: !Sub '{{resolve:ssm:/${CreatorUsername}/${EnvType}/PostgresSQL/Username:1}}'
          CREATOR_USERNAME: !Ref CreatorUsername
          ENV_TYPE: !Ref EnvType
      Events:
        GetUserInfo:
          Type: Api
          Properties:
            Path: /user
            Method: get
            RestApiId: !Ref ApiGatewayApi
Run Code Online (Sandbox Code Playgroud)

aws-cloudformation aws-lambda aws-sam

1
推荐指数
1
解决办法
3584
查看次数

在 YAML cloudformation 中加入多个资源

下面是我的 Cloudformation 模板,我想添加多个资源,但出现以下错误

模板包含错误:模板格式错误:YAML 格式不正确。(第 61 行,第 1 列)

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  This template creates IoT policy - attaches to a device certificate, IoT Topic
  Rule- used to forward messages to sns based on service key, and creates
  required IAM roles for these.

Parameters:
  vpcname:
    Type: String
    Description: Enter vpcname
  vpcnamefirstletterupper:
    Type: String
    Description: Enter vpcname with camelcase, ex- "Usdevms"
  taaccountid:
    Type: String
    Description: Enter TA AccountID"
Resources:
  IoTDaasDeviceRole:
    Type: 'AWS::IAM::Role'
    Properties:
      RoleName: !Join ["",[IoTDaasDeviceRole.,!Ref vpcname]]
      MaxSessionDuration : 43200 …
Run Code Online (Sandbox Code Playgroud)

yaml amazon-web-services aws-cloudformation

1
推荐指数
1
解决办法
7874
查看次数