Aws Ec2 instance Error

I am trying to create an ec2 instances but getting error every time like Failed to connect to your instance (Via EC2 Instance Connect). I tried all the different ways to connect it, even ssh is not working. it was not working since couple of days. Please can you help with this issue please, I’m preparing for job interviews. Thanks.

Error message ( Access denied by EC2 Instance Connect. Either your AWS credentials are not valid, or you do not have access to the EC2 instance.)

If you are talking about KK playground, EC2 instance connect is not enabled here.
You must create a key pair first and download its PEM file.
Then launch the EC2 instance using the keypair you created and SSH from your workstation to the public IP of the instance, using the PEM file as the SSH key.

Why it’s not enabled? I used Ec2 instance connect in my Kode Kloud playground before. I tried connecting with pem file as well, I was getting permission denied error. Thanks

I have faced another problem with IAM, I was not able to create anything with IAM. It was showing this error. Could you please help me.

User: arn:aws:iam::769337942107:user/kk_labs_user_739786
Service: iam
Action: GetAccessKeyLastUsed
On resource(s): access
Context: AKIA3GIA5MBN22LKO3NF because no identity-based policy allows the iam:GetAccessKeyLastUsed action

  1. Launch a new instance
  2. Select create new key pair
  3. Fill out the key pair details - the PEM will be downloaded to your downloads folder.
  4. Log in to the instance’s public IP as ec2-user using the downloaded key

I have faced another problem with IAM, I was not able to create anything with IAM. It was showing this error. Could you please help me.

User: arn:aws:iam::769337942107:user/kk_labs_user_739786
Service: iam
Action: GetAccessKeyLastUsed
On resource(s): access
Context: AKIA3GIA5MBN22LKO3NF because no identity-based policy allows the iam:GetAccessKeyLastUsed action
[/quote]

IAM is not enabled in the AWS Playground.

Task: 
Change the instance type from t2.micro to t2.nano for datacenter-ec2 instance through aws-cli only.

2) Make sure the ec2 instance datacenter-ec2 is in running state after the change


Task validation is failing. Any suggestions  ?

{
    "Reservations": [
        {
            "ReservationId": "r-002876ad5a67734d4",
            "OwnerId": "211125588626",
            "Groups": [],
            "Instances": [
                {
                    "Architecture": "x86_64",
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "AttachTime": "2024-10-27T15:39:15.000Z",
                                "DeleteOnTermination": true,
                                "Status": "attached",
                                "VolumeId": "vol-08cd279d3f4261ecc"
                            }
                        }
                    ],
                    "ClientToken": "584060d5-ec7c-4ea9-9af9-e135d256ada6",
                    "EbsOptimized": false,
                    "EnaSupport": true,
                    "Hypervisor": "xen",
                    "NetworkInterfaces": [
                        {
                            "Attachment": {
                                "AttachTime": "2024-10-27T15:39:14.000Z",
                                "AttachmentId": "eni-attach-0825f6c3f20de7df5",
                                "DeleteOnTermination": true,
                                "DeviceIndex": 0,
                                "Status": "attached",
                                "NetworkCardIndex": 0
                            },
                            "Description": "",
                            "Groups": [
                                {
                                    "GroupId": "sg-0eab8db740744a5ba",
                                    "GroupName": "default"
                                }
                            ],
                            "Ipv6Addresses": [],
                            "MacAddress": "0a:ff:f5:32:51:59",
                            "NetworkInterfaceId": "eni-0f5be362c4857c17c",
                            "OwnerId": "211125588626",
                            "PrivateDnsName": "ip-172-31-29-249.ec2.internal",
                            "PrivateIpAddress": "172.31.29.249",
                            "PrivateIpAddresses": [
                                {
                                    "Primary": true,
                                    "PrivateDnsName": "ip-172-31-29-249.ec2.internal",
                                    "PrivateIpAddress": "172.31.29.249"
                                }
                            ],
                            "SourceDestCheck": true,
                            "Status": "in-use",
                            "SubnetId": "subnet-0b32b52b931abb35b",
                            "VpcId": "vpc-02acc4b37fc8d0805",
                            "InterfaceType": "interface"
                        }
                    ],
                    "RootDeviceName": "/dev/xvda",
                    "RootDeviceType": "ebs",
                    "SecurityGroups": [
                        {
                            "GroupId": "sg-0eab8db740744a5ba",
                            "GroupName": "default"
                        }
                    ],
                    "SourceDestCheck": true,
                    "StateReason": {
                        "Code": "Client.UserInitiatedShutdown",
                        "Message": "Client.UserInitiatedShutdown: User initiated shutdown"
                    },
                    "Tags": [
                        {
                            "Key": "Name",
                            "Value": "xfusion-ec2"
                        }
                    ],
                    "VirtualizationType": "hvm",
                    "CpuOptions": {
                        "CoreCount": 1,
                        "ThreadsPerCore": 1
                    },
                    "CapacityReservationSpecification": {
                        "CapacityReservationPreference": "open"
                    },
                    "HibernationOptions": {
                        "Configured": false
                    },
                    "MetadataOptions": {
                        "State": "applied",
                        "HttpTokens": "required",
                        "HttpPutResponseHopLimit": 2,
                        "HttpEndpoint": "enabled",
                        "HttpProtocolIpv6": "disabled",
                        "InstanceMetadataTags": "disabled"
                    },
                    "EnclaveOptions": {
                        "Enabled": false
                    },
                    "BootMode": "uefi-preferred",
                    "PlatformDetails": "Linux/UNIX",
                    "UsageOperation": "RunInstances",
                    "UsageOperationUpdateTime": "2024-10-27T15:39:14.000Z",
                    "PrivateDnsNameOptions": {
                        "HostnameType": "ip-name",
                        "EnableResourceNameDnsARecord": false,
                        "EnableResourceNameDnsAAAARecord": false
                    },
                    "MaintenanceOptions": {
                        "AutoRecovery": "default"
                    },
                    "CurrentInstanceBootMode": "legacy-bios",
                    "InstanceId": "i-0e91077be141a0c94",
                    "ImageId": "ami-0c101f26f147fa7fd",
                    "State": {
                        "Code": 80,
                        "Name": "stopped"
                    },
                    "PrivateDnsName": "ip-172-31-29-249.ec2.internal",
                    "PublicDnsName": "",
                    "StateTransitionReason": "User initiated (2024-10-27 16:10:21 GMT)",
                    "AmiLaunchIndex": 0,
                    "ProductCodes": [],
                    "InstanceType": "t2.nano",
                    "LaunchTime": "2024-10-27T15:39:14.000Z",
                    "Placement": {
                        "GroupName": "",
                        "Tenancy": "default",
                        "AvailabilityZone": "us-east-1b"
                    },
                    "Monitoring": {
                        "State": "disabled"
                    },
                    "SubnetId": "subnet-0b32b52b931abb35b",
                    "VpcId": "vpc-02acc4b37fc8d0805",
                    "PrivateIpAddress": "172.31.29.249"
                }
            ]
        },
        {
            "ReservationId": "r-04804f51c1038a875",
            "OwnerId": "211125588626",
            "Groups": [],
            "Instances": [
                {
                    "Architecture": "x86_64",
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "AttachTime": "2024-10-27T16:24:01.000Z",
                                "DeleteOnTermination": true,
                                "Status": "attached",
                                "VolumeId": "vol-0d84d2a801f8ada42"
                            }
                        }
                    ],
                    "ClientToken": "3e5c1e8a-3a4f-46b5-820e-ee2bf893129c",
                    "EbsOptimized": false,
                    "EnaSupport": true,
                    "Hypervisor": "xen",
                    "NetworkInterfaces": [
                        {
                            "Association": {
                                "IpOwnerId": "amazon",
                                "PublicDnsName": "ec2-54-81-250-185.compute-1.amazonaws.com",
                                "PublicIp": "54.81.250.185"
                            },
                            "Attachment": {
                                "AttachTime": "2024-10-27T16:24:00.000Z",
                                "AttachmentId": "eni-attach-007324859f5209cd0",
                                "DeleteOnTermination": true,
                                "DeviceIndex": 0,
                                "Status": "attached",
                                "NetworkCardIndex": 0
                            },
                            "Description": "",
                            "Groups": [
                                {
                                    "GroupId": "sg-0eab8db740744a5ba",
                                    "GroupName": "default"
                                }
                            ],
                            "Ipv6Addresses": [],
                            "MacAddress": "0e:97:c9:f0:1c:9f",
                            "NetworkInterfaceId": "eni-096239cf6bc342009",
                            "OwnerId": "211125588626",
                            "PrivateDnsName": "ip-172-31-46-5.ec2.internal",
                            "PrivateIpAddress": "172.31.46.5",
                            "PrivateIpAddresses": [
                                {
                                    "Association": {
                                        "IpOwnerId": "amazon",
                                        "PublicDnsName": "ec2-54-81-250-185.compute-1.amazonaws.com",
                                        "PublicIp": "54.81.250.185"
                                    },
                                    "Primary": true,
                                    "PrivateDnsName": "ip-172-31-46-5.ec2.internal",
                                    "PrivateIpAddress": "172.31.46.5"
                                }
                            ],
                            "SourceDestCheck": true,
                            "Status": "in-use",
                            "SubnetId": "subnet-02723957dc67adf2e",
                            "VpcId": "vpc-02acc4b37fc8d0805",
                            "InterfaceType": "interface"
                        }
                    ],
                    "RootDeviceName": "/dev/xvda",
                    "RootDeviceType": "ebs",
                    "SecurityGroups": [
                        {
                            "GroupId": "sg-0eab8db740744a5ba",
                            "GroupName": "default"
                        }
                    ],
                    "SourceDestCheck": true,
                    "VirtualizationType": "hvm",
                    "CpuOptions": {
                        "CoreCount": 1,
                        "ThreadsPerCore": 1
                    },
                    "CapacityReservationSpecification": {
                        "CapacityReservationPreference": "open"
                    },
                    "HibernationOptions": {
                        "Configured": false
                    },
                    "MetadataOptions": {
                        "State": "applied",
                        "HttpTokens": "required",
                        "HttpPutResponseHopLimit": 2,
                        "HttpEndpoint": "enabled",
                        "HttpProtocolIpv6": "disabled",
                        "InstanceMetadataTags": "disabled"
                    },
                    "EnclaveOptions": {
                        "Enabled": false
                    },
                    "BootMode": "uefi-preferred",
                    "PlatformDetails": "Linux/UNIX",
                    "UsageOperation": "RunInstances",
                    "UsageOperationUpdateTime": "2024-10-27T16:24:00.000Z",
                    "PrivateDnsNameOptions": {
                        "HostnameType": "ip-name",
                        "EnableResourceNameDnsARecord": false,
                        "EnableResourceNameDnsAAAARecord": false
                    },
                    "MaintenanceOptions": {
                        "AutoRecovery": "default"
                    },
                    "CurrentInstanceBootMode": "legacy-bios",
                    "InstanceId": "i-07eca78d17f4e86bf",
                    "ImageId": "ami-0c101f26f147fa7fd",
                    "State": {
                        "Code": 16,
                        "Name": "running"
                    },
                    "PrivateDnsName": "ip-172-31-46-5.ec2.internal",
                    "PublicDnsName": "ec2-54-81-250-185.compute-1.amazonaws.com",
                    "StateTransitionReason": "",
                    "AmiLaunchIndex": 0,
                    "ProductCodes": [],
                    "InstanceType": "t2.nano",
                    "LaunchTime": "2024-10-27T16:24:00.000Z",
                    "Placement": {
                        "GroupName": "",
                        "Tenancy": "default",
                        "AvailabilityZone": "us-east-1c"
                    },
                    "Monitoring": {
                        "State": "disabled"
                    },
                    "SubnetId": "subnet-02723957dc67adf2e",
                    "VpcId": "vpc-02acc4b37fc8d0805",
                    "PrivateIpAddress": "172.31.46.5",
                    "PublicIpAddress": "54.81.250.185"
                }
            ]
        }
    ]
}

~ on ☁️  (us-east-1) ➜  

From this JSON output, it says the instance is stopped.
The question requires it to be running.

i have the same issue i posted today
if u have solution please let me know