Is it possible to set a custom hostname while creating SFTP server through AWS CDK?

421 Views Asked by At

I would like to setup a simple SFTP server using AWS Transfer Family. I use AWS CDK (typescript) to set it up. I would like to use Custom Hostname (Route53 sub-domain) while creating SFTP server.

I tried following options...

  1. Adding tags from CDK does not work, aws:transfer:route53HostedZoneId and aws:transfer:customHostname. I don't know how to get the SFTP endpoint url inside CDK. Was anyone able to fetch it?

  2. Adding tags from CLI works but I don't want to write a followup script for this. And there is also a challenge to find the SFTP server that is created as part of CDK execution. This solution does not fit in my use case.

Has anyone faced this issue?

So, I want to setup AWS Transfer SFTP server, use it to transfer files and tear it down. However, I would like to keep the SFTP url same (Route53 url).

Thanks in advance!

2

There are 2 best solutions below

2
On

Yes, it is possible. This is done through tags from the CDK

SFTPServer: Type: 'AWS::Transfer::Server' Properties: Tags: - Key: "aws:transfer:customHostname" Value: !Ref CustomHostname - Key: "aws:transfer:route53HostedZoneId" Value: !Join [ '/', [ "/hostedzone", !Ref HostedZoneID] ]

It will be something like this:

    Tags.of(cfnServer).add("transfer:route53HostedZoneId", hostedZoneId);

    Tags.of(cfnServer).add("transfer:customHostname", sftpDomainName);
0
On

You probably will need to create the sftp server with the tags and also a r53 Cname record for the same domainName.

Here is a example:

    const sftpServer = new transfer.CfnServer(this, "sftp-server", {
        endpointType: "PUBLIC",
        certificate: certificate.certificateArn,
        protocols: ["SFTP"],
        tags: [
            {
                key: "transfer:customHostname",
                value: domainName,
            },
            {
                key: "transfer:route53HostedZoneId",
                value: hostedZone.hostedZoneId,
            },
        ],
    });

    const sftpRecord = new r53.CnameRecord(this, "sftp-record", {
        domainName: `${sftpServer.attrServerId}.server.transfer.us-east-1.amazonaws.com`,
        recordName: domainName,
        zone: hostedZone,
    });