2016-06-03 06:47:30    136    0    0

Prepare Virtual Machine

  • Install OS on VMware or VirtualBox

  • Startup OS, delete the symbolic link of grubenv, then copy the real grubenv file here, like this:

  1. cd /boot/grub2/
  2. rm f grubenv
  3. cp /boot/efi/EFI/centos/grubenv ./

Export VM and Upload into AWS

  • Shutdown OS, export image using OVA type.

  • Login AWS console, then upload this OVA image into S3 bucket, for example: vm-import

  • Create vmimport role

  1. aws iam create-role --role-name vmimport \
  2. --assume-role-policy-document file://trust-policy.json

Here is the content of trust-policy.json

  1. {
  2. "Version":"2012-10-17",
  3. "Statement":[
  4. {
  5. "Sid":"",
  6. "Effect":"Allow",
  7. "Principal":{
  8. "Service":"vmie.amazonaws.com"
  9. },
  10. "Action":"sts:AssumeRole",
  11. "Condition":{
  12. "StringEquals":{
  13. "sts:ExternalId":"vmimport"
  14. }
  15. }
  16. }
  17. ]
  18. }
  • Edit policy for vmiport
  1. aws iam put-role-policy --
golang    2016-05-28 15:19:05    98    0    0

1. Mail Configuration

When we have certificates for our SMTP servers, the TLSSkipVerify should be set to true. Otherwise, set to false

  1. // MailConfig contains all configuration for mail
  2. type MailConfig struct {
  3. AuthMailAddr string
  4. AuthPassword string
  5. SendFrom string
  6. SMTPHost string
  7. TLSSkipVerify bool
  8. }
  9. var config MailConfig
  10. func SendMail(mailto string, subject string, body string) error {
  11. // Code
  12. }

2. Set From and To

  1. from := mail.Address{
  2. Name: "",
  3. Address: config.SendFrom,
  4. }
  5. to := mail.Address{
  6. Name: "",
  7. Address: mailto,
  8. }

3. Setup Header and Message

  1. // Setup headers
  2. headers := make(map[string]string)
  3. headers["From"] = from.String()
  4. headers["To"] = to.String()
  5. headers["Subject"] = subject
  6. // Setup message
  7. message := ""
  8. for k, v := range headers {
  9. message += fmt.Sprintf("%s: %s\r\n", k, v)
  10. }
  11. message += "