### Merge and Analyze Instance Data Source: https://fck-nat.dev/stable/choosing_an_instance_size This `jq` command merges the networking and pricing data, filters for instances with baseline bandwidth and positive pricing, calculates effective maximum egress bandwidth (considering vCPU limits), derives a 'value' ratio (Gbps per dollar), and computes monthly pricing. The results are sorted by value and saved to `instance-merged.json`. ```bash jq -s '.[0] * .[1]' instance-pricing.json instance-networking.json \ | jq 'with_entries(select(.value | has("baseline") and has("price") and .price > 0.0))' \ | jq 'to_entries | map(.value |= . + {max_egress: (if .vcpus < 32 then ([.baseline, 5.0] | min) else .baseline / 2 end) }) | map(.value |= . + {ratio: (.max_egress / (.price | tonumber)), price_monthly: (.price * 730)}) | sort_by(.value.ratio) | from_entries' > instance-merged.json ``` -------------------------------- ### Fetch EC2 Instance Pricing Information Source: https://fck-nat.dev/stable/choosing_an_instance_size This script retrieves on-demand pricing for EC2 instances in 'US East (N. Virginia)' using the AWS Pricing API and `jq`. It filters for 'Compute Instance' product family and extracts the USD price per hour, saving it to `instance-pricing.json`. ```bash aws pricing get-products \ --service-code AmazonEC2 \ --filters "Type=TERM_MATCH,Field=location,Value=US East (N. Virginia)" \ --region us-east-1 \ | jq -rc '.PriceList[]' \ | jq -rc 'select(.product.productFamily=="Compute Instance")' \ | jq -r '{ (.product.attributes.instanceType): { price: (.terms.OnDemand[].priceDimensions[].pricePerUnit.USD | tonumber) }}' \ | jq -s add > instance-pricing.json ``` -------------------------------- ### Fetch EC2 Instance Network Information Source: https://fck-nat.dev/stable/choosing_an_instance_size This script uses the AWS CLI to describe EC2 instance types and `jq` to extract the instance type, vCPUs, baseline bandwidth, and burst network performance. The output is saved to `instance-networking.json`. ```bash aws ec2 describe-instance-types \ --output json \ | jq '.InstanceTypes[] | { (.InstanceType): { vcpus: .VCpuInfo.DefaultVCpus, baseline: .NetworkInfo.NetworkCards[0].BaselineBandwidthInGbps, burst: .NetworkInfo.NetworkPerformance}}' \ | jq -s add > instance-networking.json ``` -------------------------------- ### CloudFormation Template for fck-nat Deployment Source: https://fck-nat.dev/stable/deploying This CloudFormation template defines the resources required to deploy fck-nat within your VPC. It includes parameters for VPC, subnet, CIDR, and AMI IDs, and provisions a network interface, IAM role, launch template, Auto Scaling Group, and security group. The UserData script configures the fck-nat service with the network interface ID. ```yaml Parameters: VpcIdParameter: Type: AWS::EC2::VPC::Id SubnetIdParameter: Type: AWS::EC2::Subnet::Id CIDRParameter: Type: String Default: "10.0.0.0/16" FckNatAMIParameter: Type: AWS::EC2::Image::Id Resources: FckNatInterface: Type: AWS::EC2::NetworkInterface Properties: Description: FckNat Gateway Interface SubnetId: !Ref SubnetIdParameter GroupSet: - !GetAtt [FckNatSecurityGroup, GroupId] SourceDestCheck: false FckNatAsgInstanceProfile: Type: AWS::IAM::InstanceProfile Properties: Roles: - !Ref FckNatRole FckNatLaunchTemplate: Type: AWS::EC2::LaunchTemplate DependsOn: FckNatRole Properties: LaunchTemplateName: FckNatLaunchTemplate LaunchTemplateData: ImageId: !Ref FckNatAMIParameter InstanceType: t4g.nano NetworkInterfaces: - DeviceIndex: 0 AssociatePublicIpAddress: true Groups: - !GetAtt [FckNatSecurityGroup, GroupId] IamInstanceProfile: Name: !Ref FckNatAsgInstanceProfile UserData: Fn::Base64: !Sub | #!/bin/bash echo "eni_id=${FckNatInterface}" >> /etc/fck-nat.conf service fck-nat restart FckNatAsg: Type: AWS::AutoScaling::AutoScalingGroup Properties: MaxSize: "1" MinSize: "1" DesiredCapacity: "1" LaunchTemplate: LaunchTemplateId: !Ref FckNatLaunchTemplate Version: !GetAtt FckNatLaunchTemplate.LatestVersionNumber VPCZoneIdentifier: - !Ref SubnetIdParameter Tags: - Key: Name Value: fck-nat PropagateAtLaunch: true UpdatePolicy: AutoScalingScheduledAction: IgnoreUnmodifiedGroupSizeProperties: true FckNatSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Security Group for FckNat SecurityGroupIngress: - CidrIp: !Ref CIDRParameter IpProtocol: "-1" SecurityGroupEgress: - CidrIp: 0.0.0.0/0 Description: Allow all outbound traffic by default IpProtocol: "-1" VpcId: !Ref VpcIdParameter FckNatRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Statement: - Action: sts:AssumeRole Effect: Allow Principal: Service: ec2.amazonaws.com Version: "2012-10-17" Policies: - PolicyName: AttachNatEniPolicy PolicyDocument: Statement: - Action: - ec2:AttachNetworkInterface - ec2:ModifyNetworkInterfaceAttribute Effect: Allow Resource: "*" Version: "2012-10-17" - PolicyName: AssociateNatAddressPolicy PolicyDocument: Statement: - Action: - ec2:AssociateAddress - ec2:DisassociateAddress Effect: Allow Resource: "*" Version: "2012-10-17" ``` -------------------------------- ### Deploy Basic fck-nat Instance with Terraform Source: https://fck-nat.dev/stable/deploying This code snippet shows a basic deployment of fck-nat as a NAT instance using core Terraform resources. It defines an AWS AMI data source for fck-nat, creates a network interface, and then launches an EC2 instance with the specified AMI and instance type. This method may not support all advanced fck-nat features. ```terraform data "aws_ami" "fck_nat" { filter { name = "name" values = ["fck-nat-al2023-*"] } filter { name = "architecture" values = ["arm64"] } owners = ["568608671756"] most_recent = true } resource "aws_network_interface" "fck-nat-if" { subnet_id = aws_subnet.subnet_public.id security_groups = [aws_default_security_group.default_security_group.id] source_dest_check = false } resource "aws_instance" "fck-nat" { ami = data.aws_ami.fck_nat.id instance_type = "t4g.nano" network_interface { network_interface_id = aws_network_interface.fck-nat-if.id device_index = 0 } } ``` -------------------------------- ### Deploy fck-nat HA VPC with CDK (TypeScript) Source: https://fck-nat.dev/stable/deploying This code snippet demonstrates deploying a VPC with fck-nat in high-availability mode using the CDK. It configures fck-nat as the NAT provider, ensuring automatic instance replacement and all necessary routing configurations. Dependencies include the AWS CDK library and the fck-nat constructs. ```typescript const natGatewayProvider = new FckNatInstanceProvider({ instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO), }); const vpc = new Vpc(this, 'vpc', { natGatewayProvider, }); natGatewayProvider.securityGroup.addIngressRule(Peer.ipv4(vpc.vpcCidrBlock), Port.allTraffic()); ``` -------------------------------- ### Deploy fck-nat Non-HA VPC with CDK (TypeScript) Source: https://fck-nat.dev/stable/deploying This code snippet shows how to deploy a VPC using fck-nat in non-high-availability mode with the CDK. It utilizes the `NatInstanceProviderV2` construct and specifies the fck-nat machine image. This approach is suitable for basic NAT instance needs. Dependencies include the AWS CDK library. ```typescript const natGatewayProvider = new NatInstanceProviderV2({ instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO), machineImage: new LookupMachineImage({ name: 'fck-nat-al2023-*-arm64-ebs', owners: ['568608671756'], }) }) const vpc = new Vpc(this, 'vpc', { natGatewayProvider, }); natGatewayProvider.securityGroup.addIngressRule(Peer.ipv4(vpc.vpcCidrBlock), Port.allTraffic()); ``` -------------------------------- ### Deploy fck-nat with Terraform Module Source: https://fck-nat.dev/stable/deploying This code snippet illustrates deploying fck-nat using the official Terraform module. It includes essential parameters like VPC ID, subnet ID, and optional configurations for high-availability mode, Elastic IP allocation, and CloudWatch agent integration. Full documentation is available on the Terraform Registry. ```terraform module "fck-nat" { source = "RaJiska/fck-nat/aws" name = "my-fck-nat" vpc_id = "vpc-abc1234" subnet_id = "subnet-abc1234" # ha_mode = true # Enables high-availability mode # eip_allocation_ids = ["eipalloc-abc1234"] # Allocation ID of an existing EIP # use_cloudwatch_agent = true # Enables Cloudwatch agent and have metrics reported update_route_tables = true route_tables_ids = { "your-rtb-name-A" = "rtb-abc1234Foo" "your-rtb-name-B" = "rtb-abc1234Bar" } } ``` -------------------------------- ### CloudWatch Agent Configuration for fck-nat Metrics Source: https://fck-nat.dev/stable/features This JSON configuration enables the CloudWatch agent within fck-nat to collect various network, connection, and system metrics. It allows for customization of collection intervals, namespaces, and metric renaming. Ensure CloudWatch metrics costs are considered before enabling this feature. ```json { "agent": { "metrics_collection_interval": 60, "run_as_user": "root", "usage_data": false }, "metrics": { "namespace": "fck-nat", "metrics_collected": { "net": { "resources": ["ens5", "ens6"], "measurement": [ { "name": "bytes_recv", "rename": "BytesIn", "unit": "Bytes" }, { "name": "bytes_sent", "rename": "BytesOut", "unit": "Bytes" }, { "name": "packets_sent", "rename": "PacketsOutCount", "unit": "Count" }, { "name": "packets_recv", "rename": "PacketsInCount", "unit": "Count" }, { "name": "drop_in", "rename": "PacketsDropInCount", "unit": "Count" }, { "name": "drop_out", "rename": "PacketsDropOutCount", "unit": "Count" } ] }, "netstat": { "measurement": [ { "name": "tcp_syn_sent", "rename": "ConnectionAttemptOutCount", "unit": "Count" }, { "name": "tcp_syn_recv", "rename": "ConnectionAttemptInCount", "unit": "Count" }, { "name": "tcp_established", "rename": "ConnectionEstablishedCount", "unit": "Count" } ] }, "ethtool": { "interface_include": ["ens5", "ens6"], "metrics_include": [ "bw_in_allowance_exceeded", "bw_out_allowance_exceeded", "conntrack_allowance_exceeded", "pps_allowance_exceeded" ] }, "mem": { "measurement": [ { "name": "used_percent", "rename": "MemoryUsed", "unit": "Percent" } ] } }, "append_dimensions": { "InstanceId": "${aws:InstanceId}", "AutoScalingGroupName": "${aws:AutoScalingGroupName}" } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.