By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Hello! I am learning resources with boto3 in python.

0

I am not good at English. This was translated by Google Trans. If you have any difficulties with my writing, I will rewrite it. I am currently studying AWS. I am studying how to automatically create AWS infrastructure resources with boto3.

I am facing a problem. I am getting the following error in my Visual Studio Code.


raise error_class(parsed_response, operation_name) botocore.exceptions.ClientError: An error occurred (InternalError) when calling the CreateTransitGatewayPeeringAttachment operation (reached max retries: 4): An internal error has occurred

After analyzing this code, I found that it is restricting the creation of CreateTransitGatewayPeeringAttachment. (Total 4 retries)

I wonder if this is correct. If so, can this restriction be removed? I want to continue studying boto3! Below I will attach the boto3 function of CreateTransitGatewayPeeringAttachment that I created. Thank you!

#################################### ###Transit Gateway - Peering Attachment ### #################################### def create_tgw_peering_attach(region, region_name, project_name, tgw_id, target_tgw_id, target_region, target_region_name): ec2 = boto3.client('ec2', region_name=region) peer_account_id = get_account_id() response = ec2.create_transit_gateway_peering_attachment( PeerAccountId=peer_account_id, TransitGatewayId=tgw_id, PeerTransitGatewayId=target_tgw_id, PeerRegion=target_region, TagSpecifications=[{ 'ResourceType': 'transit-gateway-peering-attachment', 'Tags': [{'Key': 'Name', 'Value': f'{project_name}-{region_name}-to-{target_region_name}-TGW-Peering'}] }] ) peering_tgw_attach_id = response['TransitGatewayPeeringAttachment']['TransitGatewayAttachmentId'] print(f'CREATE Complete: Transit Gateway - Peering {region_name}to {target_region}') return peering_tgw_attach_id

asked 2 months ago76 views
2 Answers
1
Accepted Answer

Hello.

I was looking at the following document, but 'transit-gateway-peering-attachment' does not exist in the 'ResourceType' specified in "TagSpecifications".
I think it should be something like "transit-gateway-attachment".
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/create_transit_gateway_peering_attachment.html

In other words, I thought it would be necessary to write code like the following.

def create_tgw_peering_attach(region, region_name, project_name, tgw_id, target_tgw_id, target_region, target_region_name): 
    ec2 = boto3.client('ec2', region_name=region) 
    peer_account_id = get_account_id() 
    response = ec2.create_transit_gateway_peering_attachment( 
        PeerAccountId=peer_account_id, 
        TransitGatewayId=tgw_id, 
        PeerTransitGatewayId=target_tgw_id, 
        PeerRegion=target_region, 
        TagSpecifications=[
            { 
                'ResourceType': 'transit-gateway-attachment', 
                'Tags': [
                    {
                        'Key': 'Name', 
                        'Value': f'{project_name}-{region_name}-to-{target_region_name}-TGW-Peering'
                    }
                ] 
            }
        ] 
    ) 
    peering_tgw_attach_id = response['TransitGatewayPeeringAttachment']['TransitGatewayAttachmentId'] 
    print(f'CREATE Complete: Transit Gateway - Peering {region_name}to {target_region}') 
    return peering_tgw_attach_id
profile picture
EXPERT
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
  • u r right! My TagSpecifications is wrong. 'ResourceType': 'transit-gateway-attachment', here! it's right. ty for help me :3 have a good day! riku kobayashi and oleksii bebych! thank you!

1

The error you're encountering is not due to a restriction on the number of CreateTransitGatewayPeeringAttachment operations you can perform. Instead, it's an internal error on AWS's side that persisted despite multiple retry attempts.

This type of error (InternalError) usually indicates a temporary issue with AWS services. It's not something you can directly control or remove. However, there are a few things you can try:

  1. Wait and retry: Sometimes, these errors resolve themselves after a short period. You could implement a backoff strategy in your code to wait for increasingly longer periods between retries.

  2. Check AWS service health: Verify if there are any ongoing issues with EC2 or Transit Gateway services in your region on the AWS Service Health Dashboard.

  3. Verify your inputs: Double-check that all the parameters you're passing to the create_transit_gateway_peering_attachment function are correct, especially the TransitGatewayId, PeerTransitGatewayId, and PeerRegion.

  4. Check your permissions: Ensure that your AWS credentials have the necessary permissions to create transit gateway peering attachments.

  5. Contact AWS Support: If the issue persists, you may need to reach out to AWS Support for further assistance.

Your code structure for creating the transit gateway peering attachment looks correct. The error is not due to your implementation, but rather an issue on AWS's side. Keep practicing with boto3, and don't be discouraged by temporary service issues!
Sources
Systems Manager examples using SDK for Python (Boto3) - AWS SDK Code Examples
API Gateway examples using SDK for Python (Boto3) - AWS SDK Code Examples

profile picture
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
  • Thanks for your answer. I ran this function code again after about 6 hours. But the result is the same. But I will keep trying.

    [1]. I did it after 6 hours, but the error result is the same. [2]. I will check it today! [3]. All parameters are considered correct. [4]. I tested it with root ID. But the result is the same as [1]. [5]. I will try this today too!

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