Skip to content

Commit

Permalink
Merge pull request #10 from chloe-codes1/docs
Browse files Browse the repository at this point in the history
Update README.md & downgrade go version
  • Loading branch information
chloe-codes1 committed Sep 26, 2021
2 parents c174ad2 + 5397be7 commit f2c327d
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
strategy:
matrix:
go-version: [~1.11, ^1]
go-version: [1.15.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# AWSCTL

[![Go Report Card](https://goreportcard.com/badge/github.com/chloe-codes1/awsctl)](https://goreportcard.com/report/github.com/chloe-codes1/awsctl) [![Coverage Status](https://coveralls.io/repos/github/chloe-codes1/awsctl/badge.svg?branch=main)](https://coveralls.io/github/chloe-codes1/awsctl?branch=main)

> 👩🏻‍🔧 Manage your AWS resources easily and efficiently
<br>
<br>

```
```AsciiDoc
_ _
| | | |
__ ___ _____ ___| |_| |
Expand Down
5 changes: 3 additions & 2 deletions cmd/get_lambda_with_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ package cmd

import (
"awsctl/pkg/lambda"

"github.com/spf13/cobra"
)

// getLambdaWithVpcCmd represents the getLambdaWithVpc command
// getLambdaWithVpcCmd represents the getLambdaWithVpc command.
var getLambdaWithVpcCmd = &cobra.Command{
Use: "get-lambda-with-vpc",
Short: "Get Lambda functions with VPC configured",
Long: ``,
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
lambda.GetLambdaWithVpc()
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/list_asg_in_specific_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra"
)

// listAsgInSpecificSubnetCmd represents the listAsgInSpecificSubnet command
// listAsgInSpecificSubnetCmd represents the listAsgInSpecificSubnet command.
var listAsgInSpecificSubnetCmd = &cobra.Command{
Use: "list-asg-in-specific-subnet",
Short: "List Auto Scaling Group in specific subnet",
Expand Down
5 changes: 3 additions & 2 deletions cmd/modify_lambda_vpc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ package cmd

import (
"awsctl/pkg/lambda"

"github.com/spf13/cobra"
)

// modifyLambdaVpcConfigCmd represents the modifyLambdaVpcConfig command
// modifyLambdaVpcConfigCmd represents the modifyLambdaVpcConfig command.
var modifyLambdaVpcConfigCmd = &cobra.Command{
Use: "modify-lambda-vpc-config",
Short: "Modify lambda VPC subnet configurations",
Long: ``,
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
lambda.ModifyLambdaVpcConfig()
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
env string
)

// rootCmd represents the base command when called without any subcommands
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "awsctl",
Short: "Manage your AWS resources easily and efficiently",
Expand Down
79 changes: 79 additions & 0 deletions go.sum

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package config

import (
"io/ioutil"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"io/ioutil"
)

var (
VPCConf *VPCConfig
VPCConf *VPCConfig
SubnetConf *SubnetConfig
)

type AppConfig struct {
VPC VPCConfig `yaml:"vpc"`
Subnet SubnetConfig `yaml:"subnet"`
VPC VPCConfig `yaml:"vpc"`
Subnet SubnetConfig `yaml:"subnet"`
}

type VPCConfig struct{
type VPCConfig struct {
VpcID string `yaml:"VpcID"`
}

type SubnetConfig struct {
PrivateSubnet PrivateSubnetConfig `yaml:"privateSubnet"`
PrivateSubnet PrivateSubnetConfig `yaml:"privateSubnet"`
ServerlessSubnet ServerlessSubnetConfig `yaml:"serverlessSubnet"`
}

Expand Down Expand Up @@ -54,4 +55,4 @@ func readConfigBytes(data []byte) (*AppConfig, error) {
return nil, errors.Wrap(err, "unmarshal error")
}
return &appConfig, nil
}
}
5 changes: 2 additions & 3 deletions internal/connector/asg_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connector

import (
"fmt"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/autoscaling"
)
Expand All @@ -12,9 +13,7 @@ func DescribeAutoScalingGroups() []*autoscaling.Group {

err := svc.DescribeAutoScalingGroupsPages(&autoscaling.DescribeAutoScalingGroupsInput{},
func(page *autoscaling.DescribeAutoScalingGroupsOutput, _ bool) bool {
for _, asg := range page.AutoScalingGroups {
result = append(result, asg)
}
result = append(result, page.AutoScalingGroups...)
return true
},
)
Expand Down
3 changes: 1 addition & 2 deletions internal/connector/aws_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
var c = AWSClient{}

type AWSClient struct {
session *session.Session
LambdaService *lambda.Lambda
ASGService *autoscaling.AutoScaling
ASGService *autoscaling.AutoScaling
}

func getSession() *session.Session {
Expand Down
22 changes: 11 additions & 11 deletions internal/connector/lambda_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package connector
import (
"awsctl/internal/config"
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/lambda"
)

// Returns only the first 50 lambdas
func ListFunctions() lambda.ListFunctionsOutput{
// Returns only the first 50 lambdas.
func ListFunctions() lambda.ListFunctionsOutput {
svc := GetLambdaService()
result, err := svc.ListFunctions(&lambda.ListFunctionsInput{
MaxItems: aws.Int64(123),
Expand All @@ -33,22 +34,22 @@ func ListFunctions() lambda.ListFunctionsOutput{
return *result
}

// Return all lambdas
// Return all lambdas.
func ListFunctionsPages() []*lambda.FunctionConfiguration {
svc := GetLambdaService()
var result []*lambda.FunctionConfiguration
err := svc.ListFunctionsPages(&lambda.ListFunctionsInput{},
func(page *lambda.ListFunctionsOutput, lastPage bool) bool {
result = append(result, page.Functions...)
return !lastPage
})
func(page *lambda.ListFunctionsOutput, lastPage bool) bool {
result = append(result, page.Functions...)
return !lastPage
})
if err != nil {
return nil
}
return result
}

func GetFunction(funcName string) lambda.GetFunctionOutput{
func GetFunction(funcName string) lambda.GetFunctionOutput {
svc := GetLambdaService()
result, err := svc.GetFunction(&lambda.GetFunctionInput{
FunctionName: aws.String(funcName),
Expand All @@ -68,14 +69,13 @@ func GetFunction(funcName string) lambda.GetFunctionOutput{
fmt.Println(aerr.Error())
}
} else {

fmt.Println(err.Error())
}
}
return *result
}

func UpdateFunctionConfiguration(funcName string) *lambda.FunctionConfiguration{
func UpdateFunctionConfiguration(funcName string) *lambda.FunctionConfiguration {
svc := GetLambdaService()
input := &lambda.UpdateFunctionConfigurationInput{
FunctionName: aws.String(funcName),
Expand Down Expand Up @@ -119,4 +119,4 @@ func UpdateFunctionConfiguration(funcName string) *lambda.FunctionConfiguration{
}
}
return result
}
}
8 changes: 3 additions & 5 deletions pkg/asg/asg_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"strings"
)

func ListAsgInSpecificSubnet(){
func ListAsgInSpecificSubnet() {
var asgNames []string
for _, asg := range connector.DescribeAutoScalingGroups(){
for _, subnet := range strings.Split(*asg.VPCZoneIdentifier, ","){

for _, asg := range connector.DescribeAutoScalingGroups() {
for _, subnet := range strings.Split(*asg.VPCZoneIdentifier, ",") {
switch subnet {
case
config.SubnetConf.PrivateSubnet.AZone,
Expand All @@ -26,7 +25,6 @@ func ListAsgInSpecificSubnet(){
}
asgNames = append(asgNames, asgName)
fmt.Println("ASG: ", asgName, " LB: ", lbName)
break
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/lambda/lambda_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ import (
"fmt"
)

func GetLambdaWithVpc() []string{
var functions []string
func GetLambdaWithVpc() []string {
var functions []string

for _, function := range connector.ListFunctionsPages(){
functionName := *function.FunctionName
funcInfo := connector.GetFunction(functionName)
vpcConfig := funcInfo.Configuration.VpcConfig
if vpcConfig != nil && *vpcConfig.VpcId == config.VPCConf.VpcID {
for _, subnetID := range vpcConfig.SubnetIds{
switch *subnetID {
for _, function := range connector.ListFunctionsPages() {
functionName := *function.FunctionName
funcInfo := connector.GetFunction(functionName)
vpcConfig := funcInfo.Configuration.VpcConfig
if vpcConfig != nil && *vpcConfig.VpcId == config.VPCConf.VpcID {
for _, subnetID := range vpcConfig.SubnetIds {
switch *subnetID {
case
config.SubnetConf.PrivateSubnet.AZone,
config.SubnetConf.PrivateSubnet.BZone,
config.SubnetConf.PrivateSubnet.CZone,
config.SubnetConf.PrivateSubnet.DZone:

functions = append (functions, functionName)
functions = append(functions, functionName)
fmt.Println(functionName)
}
}
}
}
}
fmt.Println("Number of Lambdas in Private Subnet?", len(functions))
return functions
}
fmt.Println("Number of Lambdas in Private Subnet?", len(functions))
return functions
}

func ModifyLambdaVpcConfig(){
func ModifyLambdaVpcConfig() {
functions := GetLambdaWithVpc()
for _, function := range functions{
for _, function := range functions {
connector.UpdateFunctionConfiguration(function)
}
}

0 comments on commit f2c327d

Please sign in to comment.