TTL field not supported in Step Functions SDK service integration with Route 53

0

I tried to write a step function which upsert a DNS A record on Route 53. However, the field TTL is not supported by step function:

"cause": "An error occurred while executing the state 'UpsertARecord' (entered at the event id #9). The Parameters '{\"HostedZoneId\":\"xxxxxxxxxxxxxxxxxxx\",\"ChangeBatch\":{\"Changes\":[{\"Action\":\"UPSERT\",\"ResourceRecordSet\":{\"Name\":\"xxx.yyy.domain.\",\"Type\":\"A\",\"ResourceRecords\":[{\"Value\":\"10.0.0.36\"}],\"TTL\":300}}]}}' could not be used to start the Task: [The field \"TTL\" is not supported by Step Functions]"

However, this field seems to be required by the API ChangeResourceRecordSets.

"cause": "Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found none in Change with [Action=UPSERT, Name=xxx.yyy.domain., Type=A, SetIdentifier=null] (Service: Route53, Status Code: 400, Request ID: d5ae58b1-e5bf-4365-a9b4-991c3736eabc)"

It is the state involved:

    "UpsertARecord": {
      "Type": "Task",
      "Resource": "arn:aws:states:::aws-sdk:route53:changeResourceRecordSets",
      "Parameters": {
        "HostedZoneId": "xxxxxxxxxxxxxxxxxxx",
        "ChangeBatch": {
          "Changes": [
            {
              "Action": "UPSERT",
              "ResourceRecordSet": {
                "Name": "xxx.yyy.domain.",
                "Type": "A",
                "TTL.$": "$.TTL.TTL",
                "ResourceRecords": [
                  {
                    "Value.$": "$.InstanceDetail.Reservations[0].Instances[0].PrivateIpAddress"
                  }
                ]
              }
            }
          ]
        }
      },
      "ResultPath": "$.ChangeInfo",
      "Next": "CheckStatus"
    },

Besides using a Lambda function instead, are there any alternatives if I want to keep using Step Function?

2 Answers
2
Accepted Answer

I also encountered the same problem and found this page. To resolve it, you just need to use "Ttl" instead of "TTL".

    "UpsertARecord": {
      "Type": "Task",
      "Resource": "arn:aws:states:::aws-sdk:route53:changeResourceRecordSets",
      "Parameters": {
        "HostedZoneId": "yourHostedZoneId",
        "ChangeBatch": {
          "Changes": [
            {
              "Action": "UPSERT",
              "ResourceRecordSet": {
                "Name": "aaa.bbb.domain.",
                "Type": "A",
                "Ttl.$": "$.TTL.TTL",
                "ResourceRecords": [
                  {
                    "Value.$": "$.InstanceDetail.Reservations[0].Instances[0].PrivateIpAddress"
                  }
                ]
              }
            }
          ]
        }
      },
      "ResultPath": "$.ChangeInfo",
      "Next": "CheckStatus"
    },

The input should look like this.

{
    "TTL": { "TTL": 300 }
}
profile picture
raiha
answered 9 months ago
0

TTL field is not directly supported by Step Functions, but you can still use Step Functions . you can use an AWS SDK Lambda function to call the Route 53 API.

just an example please modify

Lambda function

import json
import boto3

route53 = boto3.client('route53')

def lambda_handler(event, context):
    hosted_zone_id = event['HostedZoneId']
    change_batch = event['ChangeBatch']
    
    response = route53.change_resource_record_sets(
        HostedZoneId=hosted_zone_id,
        ChangeBatch=change_batch
    )
    
    return response

Add the necessary permissions to the Lambda (AmazonRoute53FullAccess policy or a custom policy that allows the route53:ChangeResourceRecordSets)

Step Function

"UpsertARecord": {
  "Type": "Task",
  "Resource": "arn:aws:lambda:<REGION>:<ACCOUNT_ID>:function:<YOUR_LAMBDA_FUNCTION_NAME>",
  "Parameters": {
    "HostedZoneId": "xxxxxxxxxxxxxxxxxxx",
    "ChangeBatch": {
      "Changes": [
        {
          "Action": "UPSERT",
          "ResourceRecordSet": {
            "Name": "xxx.yyy.domain.",
            "Type": "A",
            "TTL.$": "$.TTL.TTL",
            "ResourceRecords": [
              {
                "Value.$": "$.InstanceDetail.Reservations[0].Instances[0].PrivateIpAddress"
              }
            ]
          }
        }
      ]
    }
  },
  "ResultPath": "$.ChangeInfo",
  "Next": "CheckStatus"
}

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions