❚ AWS 자원 조회

go sdk app

❚ 진행 배경

❚ 사용 기술

Backend : Go, Go AWS SDK
Frontend : Javascript, HTML, CSS

❚ 주요 기능

❚ 구현 시 고려사항 :

❚ 진행 상태

❚ 테스트

go sdk app

❚ Aws Profile 관리

# IAM Role with permission policies :
#		Create role > Add Permissions

AmazonEC2FullAccess
	Provides full access to Amazon EC2 via the AWS Management Console.

IAMFullAccess
	Provides full access to IAM via the AWS Management Console.

AmazonEC2ContainerRegistryFullAccess
	Provides administrative access to Amazon ECR resources

AmazonS3FullAccess
	Provides full access to all buckets via the AWS Management Console.

ReadOnlyAccess
	Provides read-only access to AWS services and resources.

AmazonSESFullAccess
	Provides full access to Amazon SES via the AWS Management Console.

AmazonAPIGatewayAdministrator
	Provides full access to create/edit/delete APIs in Amazon API Gateway via the AWS Management Console.

AmazonECS_FullAccess
	Provides administrative access to Amazon ECS resources and enables ECS features through access to other AWS service resources, including VPCs, Auto Scaling groups, and CloudFormation stacks.

AWSCloudFormationFullAccess
	Provides full access to AWS CloudFormation.

AWSLambda_FullAccess
	Grants full access to AWS Lambda service, AWS

❚ Credential 접근: go aws sdk

import "github.com/aws/aws-sdk-go/aws/session"

// AWS 프로파일 명 (~/.aws/config)
type AwsProfile struct{
	dev string
	stg string
	prd string
}
var awsProfile AwsProfile

// 세션객체 초기화
func InitSession(profile string) *session.Session {
	if profile == "dev" {
		profile = awsProfile.dev
	} else if profile == "stg" {
		profile = awsProfile.stg
	} else if profile == "prd" {
		profile = awsProfile.prd
	}
	sess, err := session.NewSessionWithOptions(session.Options{
		// Specify profile to load for the session's config
		Profile: profile,
		SharedConfigState: session.SharedConfigEnable,
	})
	if err != nil {
		panic(err)
	}
	return sess
}

❚ 구조체 Repo 정의
❚ Repo 반환 인터페이스 정의
❚ Repo 구조체 구현 메소드 정의

// 세션 리포지토리
type Repo struct {
	sess *session.Session
}

// 세션 리포지토리 인터페이스
func RepoInterface(param *session.Session) *Repo {
	return &Repo{sess: param}
}

/**
 * 세션 리포지토리 Repo 구현체
 */

// TG 조회 -> tgMap 저장
func (repo *Repo) getAWSTargetGroups() {

	// 데이터 초기화
	tgMap = make(map[string]*elbv2.TargetGroup)

	// ELBV2 서비스 생성
	svc := elbv2.New(repo.sess)
	input := &elbv2.DescribeTargetGroupsInput{ // 요청 파라미터
		Names: []*string {
			// aws.String("awsdc-tg-erp-dev-tdms-7080"),
		},
	}
	// ELBV2 서비스 api DescribeTargetGroups 호출
	pageNum := 0
	// result, err := svc.DescribeTargetGroups(input)
	err := svc.DescribeTargetGroupsPages(input, func(page *elbv2.DescribeTargetGroupsOutput, lastPage bool) bool {
			pageNum++
			log.Println("PAGE result data size: ", len(page.TargetGroups))
			for _, tg := range page.TargetGroups {
				tgMap[*tg.TargetGroupName] = tg
			}
			return !lastPage
	})
	if err != nil {
		handleError(err)
		return
	}
}

❚ 컨테이너화