如何使用 Cloudformation 创建具有面向互联网的 VPC 端点的 AWS SFTP 服务器?
How to create an AWS SFTP server with internet-facing VPC endpoint with Cloudformation?
我能够在 VPC 内创建一个 SFTP 服务器(AWS 传输系列),在 AWS 控制台上有一个面向互联网的端点,如下所述:https://docs.aws.amazon.com/transfer/latest/userguide/create-server-in-vpc.html
VPC endpoint type access selection
现在,我需要在 CloudFormation 模板中复制完全相同的创建,但不知道该怎么做(如果可能)。根据我在 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-transfer-server-endpointdetails.html and in the corresponding CDK docs https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-transfer.CfnServer.EndpointDetailsProperty.html 中看到的内容,似乎没有设置“访问”属性 值的方法。
我遇到的所有示例都使用 PUBLIC 端点(与 VPC 端点相反)。这是我正在处理的片段:
"Resources": {
"ftpserver": {
"Type": "AWS::Transfer::Server",
"DependsOn": "sftpEIP1",
"Properties": {
"EndpointDetails": {
"SubnetIds": [
{
"Ref": "sftpSubnet1"
}
],
"VpcId": {
"Ref": "sftpVPC"
}
},
"EndpointType": "VPC",
"Protocols": [
"SFTP"
],
"Tags": [
{
"Key": "KeyName",
"Value": "ValueName"
}
]
}
}
},
...
}
由于无法在 CloudFormation 中设置访问类型,端点最终创建为“内部”而不是我需要的“面向 Internet”。
有什么办法解决这个问题,还是我应该在每次部署后手动更改它(AWS 控制台)?
您需要关联弹性IP并定义安全组。
注意,因为弹性 IP 只能在服务器创建后添加,需要一些时间才能完成,CloudFormation 实际上只创建内部服务器,停止服务器,添加弹性 IP,它再次启动弹性 IP并面向互联网,然后堆栈完成。
下面的 CF 模板示例按预期工作。
Description: Test CF with FTP server
Resources:
ElasticIP1:
Type: AWS::EC2::EIP
ElasticIP2:
Type: AWS::EC2::EIP
ElasticIP3:
Type: AWS::EC2::EIP
FTPServer:
Type: AWS::Transfer::Server
Properties:
EndpointDetails:
AddressAllocationIds:
- !GetAtt ElasticIP1.AllocationId
- !GetAtt ElasticIP2.AllocationId
- !GetAtt ElasticIP3.AllocationId
SecurityGroupIds:
- sg-0c4184c3f5da91d4a
SubnetIds:
- subnet-0546e2c78cebd0a60
- subnet-0114560b841c91de7
- subnet-0af8fb5fae5472862
VpcId: vpc-07daf77a355f5a8e8
EndpointType: VPC
Protocols:
- SFTP
我能够在 VPC 内创建一个 SFTP 服务器(AWS 传输系列),在 AWS 控制台上有一个面向互联网的端点,如下所述:https://docs.aws.amazon.com/transfer/latest/userguide/create-server-in-vpc.html
VPC endpoint type access selection
现在,我需要在 CloudFormation 模板中复制完全相同的创建,但不知道该怎么做(如果可能)。根据我在 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-transfer-server-endpointdetails.html and in the corresponding CDK docs https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-transfer.CfnServer.EndpointDetailsProperty.html 中看到的内容,似乎没有设置“访问”属性 值的方法。
我遇到的所有示例都使用 PUBLIC 端点(与 VPC 端点相反)。这是我正在处理的片段:
"Resources": {
"ftpserver": {
"Type": "AWS::Transfer::Server",
"DependsOn": "sftpEIP1",
"Properties": {
"EndpointDetails": {
"SubnetIds": [
{
"Ref": "sftpSubnet1"
}
],
"VpcId": {
"Ref": "sftpVPC"
}
},
"EndpointType": "VPC",
"Protocols": [
"SFTP"
],
"Tags": [
{
"Key": "KeyName",
"Value": "ValueName"
}
]
}
}
},
...
}
由于无法在 CloudFormation 中设置访问类型,端点最终创建为“内部”而不是我需要的“面向 Internet”。
有什么办法解决这个问题,还是我应该在每次部署后手动更改它(AWS 控制台)?
您需要关联弹性IP并定义安全组。
注意,因为弹性 IP 只能在服务器创建后添加,需要一些时间才能完成,CloudFormation 实际上只创建内部服务器,停止服务器,添加弹性 IP,它再次启动弹性 IP并面向互联网,然后堆栈完成。
下面的 CF 模板示例按预期工作。
Description: Test CF with FTP server
Resources:
ElasticIP1:
Type: AWS::EC2::EIP
ElasticIP2:
Type: AWS::EC2::EIP
ElasticIP3:
Type: AWS::EC2::EIP
FTPServer:
Type: AWS::Transfer::Server
Properties:
EndpointDetails:
AddressAllocationIds:
- !GetAtt ElasticIP1.AllocationId
- !GetAtt ElasticIP2.AllocationId
- !GetAtt ElasticIP3.AllocationId
SecurityGroupIds:
- sg-0c4184c3f5da91d4a
SubnetIds:
- subnet-0546e2c78cebd0a60
- subnet-0114560b841c91de7
- subnet-0af8fb5fae5472862
VpcId: vpc-07daf77a355f5a8e8
EndpointType: VPC
Protocols:
- SFTP