当您在控制台中创建堆栈时,控制台会按输入参数的逻辑 ID 按字母顺序列出输入参数。有一种方法可以使用界面自定义订单。
但是有什么办法可以按照模板中提到的参数来排序吗?
我定义了以下 Cloudformation 模板,我想在其中从参数文件传递公钥。“MyPublicKey”变量是字符串类型。我通过使用引用这个变量
EncodedKey !Ref MyPublicKey
Run Code Online (Sandbox Code Playgroud)
在 PublicKeyConfig 下,如下所示。
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
MyPublicKey:
Type: String
Description: 'Public key for some purpose'
NoEcho: true
Resources:
CloudfrontPublicKey:
Type: AWS::CloudFront::PublicKey
Properties:
PublicKeyConfig:
CallerReference: 'some-caller-reference'
Comment: 'Public key for signed url'
Name: 'cloudfront-public-key'
EncodedKey: !Ref MyPublicKey
...
Run Code Online (Sandbox Code Playgroud)
parameter.json 文件看起来像这样。公钥在原始 .pem 文件中是多行,但我在字符串中有换行符的地方添加了新行字符“\n”。
[
{
"ParameterKey": "MyPublicKey",
"ParameterValue": "-----BEGIN PUBLIC KEY-----\naaaa\nbbbb\n-----END PUBLIC KEY-----"
},
]
Run Code Online (Sandbox Code Playgroud)
当尝试更新堆栈时,我收到以下错误:
Invalid request provided: AWS::CloudFront::PublicKey
Run Code Online (Sandbox Code Playgroud)
似乎无法导入公钥。
我正在为我的公司开发一个应用程序,该应用程序利用带有 lambda 函数的 API 网关 REST 端点和 cognito 用户池(带有组)进行授权。
我昨天尝试添加一个新端点,收到了角色策略太大(超过 X 字节)的错误 - 在研究此问题后,我发现较新版本的 AWS amplify CLI(即 4.50.0)通过整合来规避此问题并结合类似的内联策略来减少总大小。
我升级到此版本的 Amplify CLI,发现这个问题已得到解决,但随后我遇到了另一个问题...在尝试通过 推送任何更改时amplify push,我现在收到以下错误:
Parameters: [unauthRoleName, authRoleName] do not exist in the template
这个错误指的是什么“模板”,我该如何解决它?在谷歌搜索后,我看到了一些潜在的解决方案,但没有一个真正对我有用,而对于那些确实有用的人来说,这只是一个临时解决方案。最终,如果我需要继续做一些事情作为临时修复,那么我会接受它并且它会做,但我想知道如何永久解决这个问题,因为我认为肯定缺少一些东西无论是在我这边还是在 AWS 云上...也许是升级 CLI 之前遇到的初始错误的产物?
感谢您的帮助,非常感谢:)
amazon-web-services aws-cloudformation amazon-cognito aws-lambda aws-amplify
我尝试!If在部分中使用条件resources但失败了。我想控制是否设置provisionedConcurrency我的 lambda。lambda 在function节 下定义。
functions:
getTransactionsHandler:
...
resources:
Conditions:
CommonPCNotZero: !Not [!Equals [0, '${self:custom.commonPC}']]
Resources:
!If
- CommonPCNotZero
- getTransactionsHandler:
Type: AWS::Lambda::Alias
Properties:
FunctionName: !Ref GetTransactionsHandlerLambdaFunction
FunctionVersion: !Join ['', [!Ref GetTransactionsHandlerLambdaFunction, ':$LATEST']]
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: '${self:custom.commonPC}'
- !Ref AWS::NoValue
Run Code Online (Sandbox Code Playgroud)
运行时出现以下错误sls deploy:
Error: The CloudFormation template is invalid: Template format error: [/Resources/Fn::If] resource definition is malformed
Run Code Online (Sandbox Code Playgroud)
使用条件的正确方法是什么!if?
amazon-web-services aws-cloudformation aws-lambda serverless-framework
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: must be the name of an existing EC2 KeyPair.
MySubnet:
Description: My subnet from my VPC
Type: 'AWS::EC2::Subnet::Id'
Default: subnet-YYYYYYYY
MySG:
Description: My Security Group from my VPC
Type: 'AWS::EC2::SecurityGroup::GroupName'
Default: SG-YYYYYYYY
Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-09e67e426f25ce0d7
SecurityGroups: !Ref MySG
SubnetId: !Ref MySubnet
KeyName: !Ref KeyName
Run Code Online (Sandbox Code Playgroud)
我有上面的 cloudformation 模板代码,它返回“属性 SecurityGroups 的值必须是字符串列表类型”,我的 vpc 和安全组在不同的 cloudformation 模板中进行了简化,并且我想在特定的安全组中启动 ec2。
我正在尝试将手动创建的服务转换为 cloudformation 模板,但我不断收到错误。
任务定义已使用 UI 创建,因为它需要一些特定角色
这个模板给了我:Classic Load Balancers are not supported with Fargate
ServicesSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for cluster services
VpcId: !Ref 'VPC'
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 0
ToPort: 65535
SourceSecurityGroupId: !Ref "PublicLoadBalancerSG"
ServiceStaging:
Type: AWS::ECS::Service
Properties:
ServiceName: pouch-svc-staging
TaskDefinition: pouch-td-staging:4
Cluster: !Ref 'ClusterECS'
DesiredCount: 2
SchedulingStrategy: REPLICA
LaunchType: FARGATE
EnableECSManagedTags: true
DeploymentConfiguration:
MinimumHealthyPercent: 100
MaximumPercent: 200
DeploymentCircuitBreaker:
Enable: false
Rollback: false
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
Subnets:
- !Ref PublicSubnetOne
- !Ref PublicSubnetTwo
SecurityGroups: …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-ecs aws-cloudformation aws-fargate aws-cloudformation-custom-resource
我正在尝试使用 cloudformation 创建一个 lambda 函数,但它需要 lambda 执行角色 - 有没有一种方法可以使用 cloudformation 生成一个函数?
在 CloudFormation 中使用 Depends On 的最佳实践是什么?我相信从我读到的内容来看,不建议在 Azure 中这样做并尽量减少它的使用。
例如,我想在 ASG 策略和 ASG 组之间建立 DependsOn 关系。
在上图中,您可以看到 ASG Policy 有一个字段AutoScalingGroupName。
因此,ASG 策略取决于 AutoScaling 组的创建。
这两者之间是否存在依赖关系?
amazon-web-services aws-cloudformation infrastructure-as-code
正在努力解决生成 VPCSecurityGroupIds 的 CloudFormation 语法(在我的例子中为 1)。我有下面的 yaml,基本上是尝试引用 GetAtt 函数内的参数 SecurityGroupName 。不幸的是,当我知道我传递了正确的 SecurityGroupName 值时,我得到“参数 [SecurityGroupName] 必须具有值”。非常感谢对此嵌套的任何见解。
Properties:
VpcSecurityGroupIds:
- "Fn::GetAtt": [ !Ref SecurityGroupName , "GroupId"]
Translates to
Properties:
VpcSecurityGroupIds:
- Fn:G:GetAtt:
- Ref: SecurityGroupName
- GroupId
Run Code Online (Sandbox Code Playgroud) 我正在尝试将记录插入到我的 aws 时间流表中。它的获取导致了访问被拒绝错误。
这是serverless.yml上的权限
- Effect: Allow
Action:
- timestream:*
Resource:
- arn:aws:timestream:${self:provider.region}:*:database/*
- arn:aws:timestream:${self:provider.region}:*:database/*/*/*
Run Code Online (Sandbox Code Playgroud)
我是 lambda 的角色详细信息。
{
"Action": [
"timestream:*"
],
"Resource": [
"arn:aws:timestream:us-east-1:*:database/*",
"arn:aws:timestream:us-east-1:*:database/*/*/*"
],
"Effect": "Allow"
},
Run Code Online (Sandbox Code Playgroud)
记录样本
{
"DatabaseName": "developmentreportsdb",
"TableName": "developmenteventstable",
"Records": [
{
"Dimensions": [
{
"Name": "accountId",
"Value": "6921e43e-266c-4adf-8a69-d90bd8743d1b"
},
{
"Name": "userId",
"Value": "6921e43e-266c-4adf-8a69-d90bd8743d1b"
}
],
"MeasureName": "ACCOUNT.NEW",
"MeasureValue": "6921e43e-266c-4adf-8a69-d90bd8743d1b",
"MeasureValueType": "VARCHAR",
"Time": "1644234263813",
"TimeUnit": "MILLISECONDS",
"Version": 1
}
]
}
Run Code Online (Sandbox Code Playgroud)
错误详情:
Error writing records: AccessDeniedException: User: arn:aws:sts::344128203239:assumed-role/development-us-east-1-lambdaRole/development-worker is not authorized …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-cloudformation serverless amazon-timestream
aws-lambda ×3
aws-cloudformation-custom-resource ×2
amazon-ec2 ×1
amazon-ecs ×1
aws-amplify ×1
aws-fargate ×1
roles ×1
serverless ×1
yaml ×1