Oaky, I'm going to have a stab at an answer. This might not get you all the way but hopefully it's a starting point.
EC2
I think the problem you are actually facing is AWS require you to authenticate to your v1000 instance with a key, but YDK is built with password authentication in mind. You could try to hack the instance and enable password authentication, but I wouldn't say this is preferable.
Looks like Netconf runs on port 830 but all the AWS guides that touch on SSH access refer to shelling into the linux instance itself, unless I've misunderstood.
Cisco's guide has a section on Connecting to the CSR 1000v Instance using SSH:
The Cisco CSR 1000v instance on AWS requires SSH for console access. To access the Cisco CSR 1000v AMI, perform the following steps [snip]
ssh -i pem-file-name ec2-user @[public-ipaddress | DNS-name ]
This doesn't mention anything about port 830
Configuring the keys for this, which is mentnioned earlier in the guide, sounds similar to setting up keys for any EC2 linux instance, and should probably work with an IAM user for that purpose as you mention.
YANG
I've searched all around for information on ydk-py and key authentication but found nothing. There is some mention of keys, but usually for accessing the system which hosts ydk-py not the connection to the Cisco box.
However the repo you linked appears to be using ydk.providers.NetconfServiceProvider which is a Python wrapper for C++ NetconfServiceProvider. According to this link, keys are supported:
private_key_path – (str) Path to private key file. Requires public_key_path field. Doesn’t allow password field. public_key_path – (str) Path to public key file. Requires private_key_path field. Doesn’t allow password field.
Let's have a look at how bgp.py implements this. It's actually in the file session_mgr.py. This code processes the arugments you pass on the command line:
parser = OptionParser(usage, formatter=HelpFormatterWithLineBreaks()) parser.add_option("-v", "--version", dest="version", help="force NETCONF version 1.0 or 1.1") parser.add_option("-u", "--user", dest="username", default="admin") parser.add_option("-p", "--password", dest="password", default="admin", help="password") parser.add_option("--proto", dest="proto", default="ssh", help="Which transport protocol to use, one of ssh or tcp") parser.add_option("--host", dest="host", default="localhost", help="NETCONF agent hostname") parser.add_option("--port", dest="port", default=830, type="int", help="NETCONF agent SSH port")
Then just below, an instance is created.
ne = NetconfServiceProvider(address=o.host, port=o.port, username = o.username, password = o.password, protocol = o.proto)
So at this stage you could try passing in private_key_path set to the PEM file of your AMI user.
However this then raises the question: why the default port 830? It seems this might be a separate keypair from what was set up previously. Or maybe I'm not understanding. Is the shell access granted to the AMI image actually netconf with keys? Perhaps someone with more Cisco knowledge could contribute to this.
Searching for documenation on changing the netconf credentials on this AWS version of CSRV1000 doesn't bring up much either. As I mentioned in the comments, there is a guide which suggests the combo is cisco1/cisco1.
Not a full solution but hopefully this is of some assistance.
bgp.pyactually contain. Did you write it or is it part of theydkpackage? Can you add the contents if short enough, or gist if longer? If these are just the credentials for an ssh connection, the port should be a default of22. However it's probably bad practice to enter passwords at the command line like this, and I don't think EC2 instances support password authentication out of the box. Perhaps with some edits to the script you could make it use key auth as you mentioned you've done before.bgp.pyis just a sample code from [github.com/CiscoDevNet/ydk-py/blob/master/core/samples/bgp.py]CSR 1000vthat is deployed inEC2 instance. I want to establish SSH connection between theEC2 instanceand my remote server based-linux using the python script which is in the link in my previous comment. If you would take a look,HOST,USERNAMEandPASSWORKare needed to establish the connection between these two. It happens that I useSSH keydownloaeded fromAWS consolein order to access to theEC2instance. The problem here, is that I don't know theEC2-USERpassword of theEC2instance.-u cisco1 -p cisco1 --port 830as per this guide which is actually for IOS XE 16.x Platforms. I've searched arond but can't find anything more specific for default user/pass combo in relation to the AMI of this.