github.com/aavshr/aws-sdk-go@v1.41.3/service/ec2instanceconnect/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package ec2instanceconnect_test 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "github.com/aavshr/aws-sdk-go/aws" 11 "github.com/aavshr/aws-sdk-go/aws/awserr" 12 "github.com/aavshr/aws-sdk-go/aws/session" 13 "github.com/aavshr/aws-sdk-go/service/ec2instanceconnect" 14 ) 15 16 var _ time.Duration 17 var _ strings.Reader 18 var _ aws.Config 19 20 func parseTime(layout, value string) *time.Time { 21 t, err := time.Parse(layout, value) 22 if err != nil { 23 panic(err) 24 } 25 return &t 26 } 27 28 // To push an SSH key to an EC2 instance 29 // 30 // The following example pushes a sample SSH public key to the EC2 instance i-abcd1234 31 // in AZ us-west-2b for use by the instance OS user ec2-user. 32 func ExampleEC2InstanceConnect_SendSSHPublicKey_shared00() { 33 svc := ec2instanceconnect.New(session.New()) 34 input := &ec2instanceconnect.SendSSHPublicKeyInput{ 35 AvailabilityZone: aws.String("us-west-2a"), 36 InstanceId: aws.String("i-abcd1234"), 37 InstanceOSUser: aws.String("ec2-user"), 38 SSHPublicKey: aws.String("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3FlHqj2eqCdrGHuA6dRjfZXQ4HX5lXEIRHaNbxEwE5Te7xNF7StwhrDtiV7IdT5fDqbRyGw/szPj3xGkNTVoElCZ2dDFb2qYZ1WLIpZwj/UhO9l2mgfjR56UojjQut5Jvn2KZ1OcyrNO0J83kCaJCV7JoVbXY79FBMUccYNY45zmv9+1FMCfY6i2jdIhwR6+yLk8oubL8lIPyq7X+6b9S0yKCkB7Peml1DvghlybpAIUrC9vofHt6XP4V1i0bImw1IlljQS+DUmULRFSccATDscCX9ajnj7Crhm0HAZC0tBPXpFdHkPwL3yzYo546SCS9LKEwz62ymxxbL9k7h09t"), 39 } 40 41 result, err := svc.SendSSHPublicKey(input) 42 if err != nil { 43 if aerr, ok := err.(awserr.Error); ok { 44 switch aerr.Code() { 45 case ec2instanceconnect.ErrCodeAuthException: 46 fmt.Println(ec2instanceconnect.ErrCodeAuthException, aerr.Error()) 47 case ec2instanceconnect.ErrCodeInvalidArgsException: 48 fmt.Println(ec2instanceconnect.ErrCodeInvalidArgsException, aerr.Error()) 49 case ec2instanceconnect.ErrCodeServiceException: 50 fmt.Println(ec2instanceconnect.ErrCodeServiceException, aerr.Error()) 51 case ec2instanceconnect.ErrCodeThrottlingException: 52 fmt.Println(ec2instanceconnect.ErrCodeThrottlingException, aerr.Error()) 53 case ec2instanceconnect.ErrCodeEC2InstanceNotFoundException: 54 fmt.Println(ec2instanceconnect.ErrCodeEC2InstanceNotFoundException, aerr.Error()) 55 default: 56 fmt.Println(aerr.Error()) 57 } 58 } else { 59 // Print the error, cast err to awserr.Error to get the Code and 60 // Message from an error. 61 fmt.Println(err.Error()) 62 } 63 return 64 } 65 66 fmt.Println(result) 67 }