{
 "Description": "Integration Test for aws-apigateway-sqs",
 "Resources": {
  "disconnectServiceRole0B1E33D9": {
   "Type": "AWS::IAM::Role",
   "Properties": {
    "AssumeRolePolicyDocument": {
     "Statement": [
      {
       "Action": "sts:AssumeRole",
       "Effect": "Allow",
       "Principal": {
        "Service": "lambda.amazonaws.com"
       }
      }
     ],
     "Version": "2012-10-17"
    },
    "Policies": [
     {
      "PolicyDocument": {
       "Statement": [
        {
         "Action": [
          "logs:CreateLogGroup",
          "logs:CreateLogStream",
          "logs:PutLogEvents"
         ],
         "Effect": "Allow",
         "Resource": {
          "Fn::Join": [
           "",
           [
            "arn:",
            {
             "Ref": "AWS::Partition"
            },
            ":logs:",
            {
             "Ref": "AWS::Region"
            },
            ":",
            {
             "Ref": "AWS::AccountId"
            },
            ":log-group:/aws/lambda/*"
           ]
          ]
         }
        }
       ],
       "Version": "2012-10-17"
      },
      "PolicyName": "LambdaFunctionServiceRolePolicy"
     }
    ]
   },
   "Metadata": {
    "guard": {
     "SuppressedRules": [
      "IAM_NO_INLINE_POLICY_CHECK"
     ]
    }
   }
  },
  "disconnect829B70D0": {
   "Type": "AWS::Lambda::Function",
   "Properties": {
    "Code": {
     "S3Bucket": {
      "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
     },
     "S3Key": "9da0e8bdfa0712cb47fc2d6c6bad128e2edc58ffe5a8af5a322914f5c63609d1.zip"
    },
    "Environment": {
     "Variables": {
      "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1"
     }
    },
    "Handler": "disconnect.handler",
    "Role": {
     "Fn::GetAtt": [
      "disconnectServiceRole0B1E33D9",
      "Arn"
     ]
    },
    "Runtime": "nodejs20.x",
    "TracingConfig": {
     "Mode": "Active"
    }
   },
   "DependsOn": [
    "disconnectServiceRole0B1E33D9"
   ],
   "Metadata": {
    "cfn_nag": {
     "rules_to_suppress": [
      {
       "id": "W58",
       "reason": "Lambda functions has the required permission to write CloudWatch Logs. It uses custom policy instead of arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole with tighter permissions."
      },
      {
       "id": "W89",
       "reason": "This is not a rule for the general case, just for specific use cases/industries"
      },
      {
       "id": "W92",
       "reason": "Impossible for us to define the correct concurrency for clients"
      }
     ]
    }
   }
  },
  "disconnectinlinePolicyAddedToExecutionRole0CDB203CB": {
   "Type": "AWS::IAM::Policy",
   "Properties": {
    "PolicyDocument": {
     "Statement": [
      {
       "Action": [
        "xray:PutTelemetryRecords",
        "xray:PutTraceSegments"
       ],
       "Effect": "Allow",
       "Resource": "*"
      }
     ],
     "Version": "2012-10-17"
    },
    "PolicyName": "disconnectinlinePolicyAddedToExecutionRole0CDB203CB",
    "Roles": [
     {
      "Ref": "disconnectServiceRole0B1E33D9"
     }
    ]
   }
  },
  "ApiGatewayV2WebSocketToSqsqueuedlq875602DF": {
   "Type": "AWS::SQS::Queue",
   "Properties": {
    "DeduplicationScope": "messageGroup",
    "FifoQueue": true,
    "FifoThroughputLimit": "perMessageGroupId",
    "KmsMasterKeyId": "alias/aws/sqs"
   },
   "UpdateReplacePolicy": "Delete",
   "DeletionPolicy": "Delete"
  },
  "ApiGatewayV2WebSocketToSqsqueuedlqPolicy9E75C5D9": {
   "Type": "AWS::SQS::QueuePolicy",
   "Properties": {
    "PolicyDocument": {
     "Statement": [
      {
       "Action": [
        "sqs:AddPermission",
        "sqs:DeleteMessage",
        "sqs:GetQueueAttributes",
        "sqs:ReceiveMessage",
        "sqs:RemovePermission",
        "sqs:SendMessage",
        "sqs:SetQueueAttributes"
       ],
       "Effect": "Allow",
       "Principal": {
        "AWS": {
         "Fn::Join": [
          "",
          [
           "arn:",
           {
            "Ref": "AWS::Partition"
           },
           ":iam::",
           {
            "Ref": "AWS::AccountId"
           },
           ":root"
          ]
         ]
        }
       },
       "Resource": {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsqueuedlq875602DF",
         "Arn"
        ]
       },
       "Sid": "QueueOwnerOnlyAccess"
      },
      {
       "Action": "SQS:*",
       "Condition": {
        "Bool": {
         "aws:SecureTransport": "false"
        }
       },
       "Effect": "Deny",
       "Principal": {
        "AWS": "*"
       },
       "Resource": {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsqueuedlq875602DF",
         "Arn"
        ]
       },
       "Sid": "HttpsOnly"
      }
     ],
     "Version": "2012-10-17"
    },
    "Queues": [
     {
      "Ref": "ApiGatewayV2WebSocketToSqsqueuedlq875602DF"
     }
    ]
   }
  },
  "ApiGatewayV2WebSocketToSqsqueue6D26A944": {
   "Type": "AWS::SQS::Queue",
   "Properties": {
    "DeduplicationScope": "messageGroup",
    "FifoQueue": true,
    "FifoThroughputLimit": "perMessageGroupId",
    "KmsMasterKeyId": "alias/aws/sqs",
    "RedriveAllowPolicy": {
     "redrivePermission": "denyAll"
    },
    "RedrivePolicy": {
     "deadLetterTargetArn": {
      "Fn::GetAtt": [
       "ApiGatewayV2WebSocketToSqsqueuedlq875602DF",
       "Arn"
      ]
     },
     "maxReceiveCount": 15
    },
    "VisibilityTimeout": 900
   },
   "UpdateReplacePolicy": "Delete",
   "DeletionPolicy": "Delete"
  },
  "ApiGatewayV2WebSocketToSqsqueuePolicyEFABA1AE": {
   "Type": "AWS::SQS::QueuePolicy",
   "Properties": {
    "PolicyDocument": {
     "Statement": [
      {
       "Action": [
        "sqs:AddPermission",
        "sqs:DeleteMessage",
        "sqs:GetQueueAttributes",
        "sqs:ReceiveMessage",
        "sqs:RemovePermission",
        "sqs:SendMessage",
        "sqs:SetQueueAttributes"
       ],
       "Effect": "Allow",
       "Principal": {
        "AWS": {
         "Fn::Join": [
          "",
          [
           "arn:",
           {
            "Ref": "AWS::Partition"
           },
           ":iam::",
           {
            "Ref": "AWS::AccountId"
           },
           ":root"
          ]
         ]
        }
       },
       "Resource": {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsqueue6D26A944",
         "Arn"
        ]
       },
       "Sid": "QueueOwnerOnlyAccess"
      },
      {
       "Action": "SQS:*",
       "Condition": {
        "Bool": {
         "aws:SecureTransport": "false"
        }
       },
       "Effect": "Deny",
       "Principal": {
        "AWS": "*"
       },
       "Resource": {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsqueue6D26A944",
         "Arn"
        ]
       },
       "Sid": "HttpsOnly"
      }
     ],
     "Version": "2012-10-17"
    },
    "Queues": [
     {
      "Ref": "ApiGatewayV2WebSocketToSqsqueue6D26A944"
     }
    ]
   }
  },
  "ApiGatewayV2WebSocketToSqsLambdaRestApiCloudWatchRole42C4E931": {
   "Type": "AWS::IAM::Role",
   "Properties": {
    "AssumeRolePolicyDocument": {
     "Statement": [
      {
       "Action": "sts:AssumeRole",
       "Effect": "Allow",
       "Principal": {
        "Service": "apigateway.amazonaws.com"
       }
      }
     ],
     "Version": "2012-10-17"
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsLambdaRestApiCloudWatchRoleDefaultPolicy6D004FA5": {
   "Type": "AWS::IAM::Policy",
   "Properties": {
    "PolicyDocument": {
     "Statement": [
      {
       "Action": [
        "sqs:GetQueueAttributes",
        "sqs:GetQueueUrl",
        "sqs:SendMessage"
       ],
       "Effect": "Allow",
       "Resource": {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsqueue6D26A944",
         "Arn"
        ]
       }
      },
      {
       "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:DescribeLogGroups",
        "logs:DescribeLogStreams",
        "logs:FilterLogEvents",
        "logs:GetLogEvents",
        "logs:PutLogEvents"
       ],
       "Effect": "Allow",
       "Resource": {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsLogGroupAD536311",
         "Arn"
        ]
       }
      }
     ],
     "Version": "2012-10-17"
    },
    "PolicyName": "ApiGatewayV2WebSocketToSqsLambdaRestApiCloudWatchRoleDefaultPolicy6D004FA5",
    "Roles": [
     {
      "Ref": "ApiGatewayV2WebSocketToSqsLambdaRestApiCloudWatchRole42C4E931"
     }
    ]
   },
   "Metadata": {
    "cfn_nag": {
     "rules_to_suppress": [
      {
       "id": "AwsSolutions-IAM5",
       "reason": "The APIGateway requires permissions to KMS so that it can write to an encrypted SQS queue"
      }
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D": {
   "Type": "AWS::ApiGatewayV2::Api",
   "Properties": {
    "Name": "WebSocketApiApiGatewayV2WebSocketToSqs",
    "ProtocolType": "WEBSOCKET",
    "RouteSelectionExpression": "$request.body.action"
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsconnectRouteconnect5AB5A82B": {
   "Type": "AWS::ApiGatewayV2::Integration",
   "Properties": {
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "IntegrationType": "MOCK",
    "IntegrationUri": ""
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsconnectRoute16EADCB5": {
   "Type": "AWS::ApiGatewayV2::Route",
   "Properties": {
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "AuthorizationType": "AWS_IAM",
    "RouteKey": "$connect",
    "Target": {
     "Fn::Join": [
      "",
      [
       "integrations/",
       {
        "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsconnectRouteconnect5AB5A82B"
       }
      ]
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdisconnectRouteDisconnectIntegrationPermission5D4CD3D3": {
   "Type": "AWS::Lambda::Permission",
   "Properties": {
    "Action": "lambda:InvokeFunction",
    "FunctionName": {
     "Fn::GetAtt": [
      "disconnect829B70D0",
      "Arn"
     ]
    },
    "Principal": "apigateway.amazonaws.com",
    "SourceArn": {
     "Fn::Join": [
      "",
      [
       "arn:",
       {
        "Ref": "AWS::Partition"
       },
       ":execute-api:",
       {
        "Ref": "AWS::Region"
       },
       ":",
       {
        "Ref": "AWS::AccountId"
       },
       ":",
       {
        "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
       },
       "/*$disconnect"
      ]
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdisconnectRouteDisconnectIntegrationFAAA34C8": {
   "Type": "AWS::ApiGatewayV2::Integration",
   "Properties": {
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "IntegrationType": "AWS_PROXY",
    "IntegrationUri": {
     "Fn::Join": [
      "",
      [
       "arn:",
       {
        "Ref": "AWS::Partition"
       },
       ":apigateway:",
       {
        "Ref": "AWS::Region"
       },
       ":lambda:path/2015-03-31/functions/",
       {
        "Fn::GetAtt": [
         "disconnect829B70D0",
         "Arn"
        ]
       },
       "/invocations"
      ]
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdisconnectRoute9D52E365": {
   "Type": "AWS::ApiGatewayV2::Route",
   "Properties": {
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "AuthorizationType": "NONE",
    "RouteKey": "$disconnect",
    "Target": {
     "Fn::Join": [
      "",
      [
       "integrations/",
       {
        "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdisconnectRouteDisconnectIntegrationFAAA34C8"
       }
      ]
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdefaultRoutedefaultB531E839": {
   "Type": "AWS::ApiGatewayV2::Integration",
   "Properties": {
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "CredentialsArn": {
     "Fn::GetAtt": [
      "ApiGatewayV2WebSocketToSqsLambdaRestApiCloudWatchRole42C4E931",
      "Arn"
     ]
    },
    "IntegrationMethod": "POST",
    "IntegrationType": "AWS",
    "IntegrationUri": {
     "Fn::Join": [
      "",
      [
       "arn:",
       {
        "Ref": "AWS::Partition"
       },
       ":apigateway:",
       {
        "Ref": "AWS::Region"
       },
       ":sqs:path/",
       {
        "Ref": "AWS::AccountId"
       },
       "/",
       {
        "Fn::GetAtt": [
         "ApiGatewayV2WebSocketToSqsqueue6D26A944",
         "QueueName"
        ]
       }
      ]
     ]
    },
    "PassthroughBehavior": "NEVER",
    "RequestParameters": {
     "integration.request.header.Content-Type": "'application/x-www-form-urlencoded'"
    },
    "RequestTemplates": {
     "$default": "Action=SendMessage&MessageGroupId=$input.path('$.MessageGroupId')&MessageDeduplicationId=$context.requestId&MessageAttribute.1.Name=connectionId&MessageAttribute.1.Value.StringValue=$context.connectionId&MessageAttribute.1.Value.DataType=String&MessageAttribute.2.Name=requestId&MessageAttribute.2.Value.StringValue=$context.requestId&MessageAttribute.2.Value.DataType=String&MessageBody=$util.urlEncode($input.json($util.escapeJavaScript('$').replaceAll(\"\\\\'\",\"'\")))"
    },
    "TemplateSelectionExpression": "\\$default"
   }
  },
  "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdefaultRouteCD89F0EF": {
   "Type": "AWS::ApiGatewayV2::Route",
   "Properties": {
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "AuthorizationType": "NONE",
    "RouteKey": "$default",
    "Target": {
     "Fn::Join": [
      "",
      [
       "integrations/",
       {
        "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqsdefaultRoutedefaultB531E839"
       }
      ]
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsStage5C419F9E": {
   "Type": "AWS::ApiGatewayV2::Stage",
   "Properties": {
    "AccessLogSettings": {
     "DestinationArn": {
      "Fn::GetAtt": [
       "ApiGatewayV2WebSocketToSqsLogGroupAD536311",
       "Arn"
      ]
     },
     "Format": "$context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] \"$context.httpMethod $context.resourcePath $context.protocol\" $context.status $context.responseLength $context.requestId"
    },
    "ApiId": {
     "Ref": "ApiGatewayV2WebSocketToSqsWebSocketApiApiGatewayV2WebSocketToSqs92E2576D"
    },
    "AutoDeploy": true,
    "DefaultRouteSettings": {
     "DataTraceEnabled": false,
     "DetailedMetricsEnabled": true,
     "LoggingLevel": "ERROR"
    },
    "StageName": "prod"
   },
   "Metadata": {
    "guard": {
     "SuppressedRules": [
      "API_GW_CACHE_ENABLED_AND_ENCRYPTED"
     ]
    },
    "cfn_nag": {
     "rules_to_suppress": [
      {
       "id": "AwsSolutions-APIG1",
       "reason": "Access logging configuration has been provided as per ApiGateway v2 requirements"
      }
     ]
    }
   }
  },
  "ApiGatewayV2WebSocketToSqsLogGroupAD536311": {
   "Type": "AWS::Logs::LogGroup",
   "UpdateReplacePolicy": "Retain",
   "DeletionPolicy": "Retain",
   "Metadata": {
    "cfn_nag": {
     "rules_to_suppress": [
      {
       "id": "W86",
       "reason": "Retention period for CloudWatchLogs LogGroups are set to 'Never Expire' to preserve customer data indefinitely"
      },
      {
       "id": "W84",
       "reason": "By default CloudWatchLogs LogGroups data is encrypted using the CloudWatch server-side encryption keys (AWS Managed Keys)"
      }
     ]
    }
   }
  }
 },
 "Parameters": {
  "BootstrapVersion": {
   "Type": "AWS::SSM::Parameter::Value<String>",
   "Default": "/cdk-bootstrap/hnb659fds/version",
   "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
  }
 },
 "Rules": {
  "CheckBootstrapVersion": {
   "Assertions": [
    {
     "Assert": {
      "Fn::Not": [
       {
        "Fn::Contains": [
         [
          "1",
          "2",
          "3",
          "4",
          "5"
         ],
         {
          "Ref": "BootstrapVersion"
         }
        ]
       }
      ]
     },
     "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
    }
   ]
  }
 }
}