标签: infrastructure-as-code

How to enable CORS with AWS SAM

I'm trying to enable CORS in my AWS SAM app. Here is the snippet from my template.yaml:

Globals:
  Api:
    Cors:
      AllowMethods: "'*'"
      AllowHeaders: "'*'"
      AllowOrigin: "'*'"

Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      Auth:
        Authorizers:
          MyCognitoAuthorizer: ...

  getByIdFunc:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/handler.handle
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /{id}
            Method: GET
            RestApiId: !Ref MyApi
Run Code Online (Sandbox Code Playgroud)

根据此Using CORS with AWS SAMhttps://github.com/aws/serverless-application-model/issues/373,cors配置应该可以工作,但不幸的是API响应上没有设置标头,如下所示。

< HTTP/2 200 
< content-type: application/json
< content-length: 770
< date: Tue, 13 Apr 2021 …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services cors aws-api-gateway aws-sam infrastructure-as-code

16
推荐指数
3
解决办法
2万
查看次数

CloudFormation 资源创建(如果不存在)

我想用 CloudFormation 创建 Route53 HostedZone,所以我想检查一下 Route53 中关于 HostedZone 的一些信息是否存在。

在我的情况下,我需要检查资源是否存在,忽略资源创建。我该如何处理这个问题。

我的 CloudFormation 模板如下所示。

"myDNSRecord" : {
  "Type" : "AWS::Route53::RecordSet",
  "Properties" : {
    "HostedZoneName" : { "Ref" : "HostedZoneResource" },
    "Comment" : "DNS name for my instance.",  
    "Name" : {
      "Fn::Join" : [ "", [
        {"Ref" : "Ec2Instance"}, ".",
        {"Ref" : "AWS::Region"}, ".",
        {"Ref" : "HostedZone"} ,"."
      ] ]
    },
    "Type" : "A",
    "TTL" : "900",
    "ResourceRecords" : [
      { "Fn::GetAtt" : [ "Ec2Instance", "PublicIp" ] }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cloudformation devops infrastructure-as-code

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

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

如何使用多个AWS帐户来隔离环境之间的Terraform状态

如何使用指向不同 AWS 账户的 s3 后端?

换句话说,我想要这样的东西:

AWS 账户 A 中 S3 存储桶的开发环境状态

AWS 账户 B 上另一个 S3 存储桶上的暂存环境状态

任何人都可以帮助我吗?

amazon-web-services terraform infrastructure-as-code

11
推荐指数
2
解决办法
1万
查看次数

AWS with Terraform - 安全组规则内的安全组参数

当您查看terraform 的安全组文档时,您可以看到有一个选项可以定义security_groups在入口/出口安全规则中定义参数。

这对我来说似乎很奇怪,但也许我在这里遗漏了一些东西。

我看到了这个帖子,但没有提到现实世界的用例。

我的问题是:在什么情况下我们会想要使用这种配置?

amazon-web-services terraform infrastructure-as-code

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

AWS CDK 多个应用程序

是否可以在同一个项目中拥有两个 CDK 应用程序,如下所示:

from aws_cdk import core

from stack1 import Stack1
from stack2 import Stack2

app1 = core.App()
Stack1(app1, "CDK1")
app1.synth()

app2 = core.App()
Stack2(app2, "CDK2")
app2.synth()
Run Code Online (Sandbox Code Playgroud)

并部署它们?同步/异步?

是否可以在另一个应用程序中引用一个应用程序中的某些资源?

amazon-web-services aws-cdk infrastructure-as-code

10
推荐指数
2
解决办法
9747
查看次数

通过 Terraform 更改 AWS 中的目标端口时,删除目标组时出错:ResourceInUse

我目前正在阅读测试版“Terraform Up & Running, 2nd Edition”。在第 2 章中,我在 AWS 中创建了一个 Auto Scaling 组和一个负载均衡器。

现在我使我的后端服务器 HTTP 端口可配置。默认情况下,它们侦听端口 8080。

variable "server_port" {
    …
    default = 8080
}

resource "aws_launch_configuration" "example" {
    …
    user_data = <<-EOF
                #!/bin/bash
                echo "Hello, World" > index.html
                nohup busybox httpd -f -p ${var.server_port} &
                EOF
    …
}

resource "aws_security_group" "instance" {
    …
    ingress {
        from_port = var.server_port
        to_port = var.server_port
        …
    }
}
Run Code Online (Sandbox Code Playgroud)

还需要在应用程序负载均衡器的目标组中配置相同的端口。

resource "aws_lb_target_group" "asg" {
    …
    port = var.server_port
    …
}
Run Code Online (Sandbox Code Playgroud)

当我的基础设施已经部署好时,例如将端口的配置设置为 8080,然后我通过运行将变量更改为 80 terraform …

cloud amazon-web-services terraform devops infrastructure-as-code

8
推荐指数
2
解决办法
7566
查看次数

适用于 IaC 的 AWS CDK VS SDK

我最近开始使用 AWS 和 IaC,我正在使用 Cloudformation 来配置我的 AWS 资源,但我发现 AWS 提供了一个 SDK 和一个 CDK,使您能够以编程方式而不是普通的 json/yaml 来配置资源。

但是根据文档,我并没有真正理解它们的不同之处,有人可以向我解释它们的不同之处以及您应该使用什么用例吗?

amazon-web-services aws-cloudformation infrastructure-as-code

8
推荐指数
2
解决办法
3438
查看次数

ARM 模板 - 自动批准托管专用端点

我正在为 Azure 数据工厂开发一个 ARM 模板,其中包含 SQL Server 和 Azure Datalake 的托管专用终结点。但是,当 ARM 模板完成执行时,托管专用端点将处于“待处理”状态。如何配置托管专用端点,以便在使用 ARM 模板完全配置 ADF 后将其配置为“已批准”。以下是我的 template.json 文件:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "environment": {
            "type": "string",
            "metadata": {
                "description": "name of environment for deployment"
            }
        },
        "project": {
            "type": "string",
            "metadata": {
                "description": "name of the project for building the name of resources"
            }
        },
        "location": {
            "defaultValue": "eastus",
            "type": "string"
        },
        "adfFactoryName": {            
            "type": "string"
        },
        "adfVersion": {            
            "type": "string"
        },
        "tags": {
            "type": "object", …
Run Code Online (Sandbox Code Playgroud)

azure azure-resource-manager azure-data-factory azure-data-lake infrastructure-as-code

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

如何在 CloudFormation 中使用基础设施即代码实现 DynamoDB 全局二级索引

我正在使用基础设施即代码在 CloudFormation 中实施 GSI。我想要做的就是使用这个表来记录主 DynamoTable 中的条目数。这是主要故事的样子:

Resources:
  CaseRecords:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: ${self:custom.tableName}
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - AttributeName: userId
          AttributeType: S
        - AttributeName: caseRecordId
          AttributeType: S
      KeySchema:
        - AttributeName: userId
          KeyType: HASH
        - AttributeName: caseRecordId
          KeyType: RANGE
Run Code Online (Sandbox Code Playgroud)

我不需要原始表中的键,我想要的只是为新 GSI 创建一个新的 HASH 键,它会告诉我我正在跟踪的计数来自哪个表,即上面的表。

以下是我迄今为止尝试实施 GSI 的方式:

# Implement a GSI to handle item count totals
      GlobalSecondaryIndexes:
          - IndexName: gsiCaseCountTable
            KeySchema: 
              - AttributeName: table-name
                KeyType: HASH
            ProvisionedThroughput:
              ReadCapacityUnits: 5
              WriteCapacityUnits: 5
Run Code Online (Sandbox Code Playgroud)

但是,我得到的错误如下:

An error occurred: CaseRecords - Property Projection cannot be empty.. …

yaml aws-cloudformation amazon-dynamodb infrastructure-as-code

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