当我删除 cloudformation 堆栈时,它不会删除其中的非空 s3 存储桶和非空日志组。
知道为什么会这样吗?我怎样才能覆盖删除它?
我在 AWS 上为不同区域提供了产品。但对于 GovCloud 区域,ARN 结构与普通区域不同。当我们使用 ARN 时,政府区域中的正常部署失败。为此,我添加了一个检查区域名称是否为 Gov 区域的检查。但我必须对区域名称进行硬编码。是否有任何通用条件来检查当前区域是 CFT 中的政府区域?
考虑示例(来源)
# 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) 我需要一些建议,我想创建一个例外,该例外将忽略 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) 我正在尝试通过 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) 我想获取具有以下标记/值的所有 CloudFormation 堆栈的堆栈名称:
elasticbeanstalk:environment-name:myenvironment
有什么办法可以做到这一点吗?我尝试了这个查询,但它引发了语法错误:
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) 我在帐户 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) 使用以下 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) 我正在创建定义我们的产品环境的模板。在我们的系统中,我们将使用许多 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) 下面是我的 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 ×3
amazon-iam ×2
amazon-kms ×1
amazon-s3 ×1
aws-cli ×1
aws-lambda ×1
aws-sam ×1
jmespath ×1