I am trying to send emails through Amazon SES in Golang. Previously it was working on a development server (without SSL) with following code:
sess, err := session.NewSession(&aws.Config{
Region:aws.String(AwsRegion)},
)
/* Create an SES client in the session */
svc := ses.New(sess)
/* Assemble the email */
input := &ses.SendEmailInput{
Destination: &ses.Destination{
CcAddresses: []*string{
},
ToAddresses: []*string{
aws.String(request.EmailTo),
},
},
Message: &ses.Message{
Body: &ses.Body{
Html: &ses.Content{
Charset: aws.String(CharSet),
Data: aws.String(body),
},
},
Subject: &ses.Content{
Charset: aws.String(CharSet),
Data: aws.String(subject),
},
},
Source: aws.String("test<test@example.com>"),
}
/* Attempt to send the email */
result, err := svc.SendEmail(input)
Recently I started working on the production server (with SSL) and the same code started giving me following error:
NoCredentialProviders: no valid providers in chain. Deprecated.
For verbose messaging see aws.Config.CredentialsChainVerboseErrors
I have tried adding credentials to the code like this:
creds := credentials.NewCredentials(&ec2rolecreds.EC2RoleProvider{})
/* updated session block with credentials in aws config */
sess, err := session.NewSession(&aws.Config{
Region: aws.String(AwsRegion),
Credentials: creds})
But this code is not working (not even compiling) and gives me following error:
/main.go:63:42: undefined: ec2rolecreds
However I have already included credentials package in code.
I am not getting how to add credentials to this code so that it works on production server too. Any kind of help will be appreciated.