为RDS ScalingConfiguration参数抛出错误

huangapple go评论88阅读模式
英文:

Throw Error for RDS ScalingConfiguration parameters

问题

我们在AWS Lambda中使用这个函数,但是我们遇到了以下错误:

运行时错误:无效的内存地址或空指针解引用:errorString
[{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/errors.go","line":39,"label":"lambdaPanicResponse"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/function.go","line":36,"label":"(Function).Invoke.func1"},{"path":"runtime/panic.go","line":679,"label":"gopanic"},{"path":"runtime/panic.go","line":199,"label":"panicmem"},{"path":"runtime/signal_unix.go","line":394,"label":"sigpanic"},{"path":"Lamda/main.go","line":55,"label":"HandlerAcus"},{"path":"reflect/value.go","line":460,"label":"Value.call"},{"path":"reflect/value.go","line":321,"label":"Value.Call"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/handler.go","line":124,"label":"NewHandler.func1"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/handler.go","line":24,"label":"lambdaHandler.Invoke"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/function.go","line":64,"label":"(Function).Invoke"},{"path":"reflect/value.go","line":460,"label":"Value.call"},{"path":"reflect/value.go","line":321,"label":"Value.Call"},{"path":"net/rpc/server.go","line":377,"label":"(*service).call"},{"path":"runtime/asm_amd64.s","line":1357,"label":"goexit"}]

代码如下:

func main() {
    lambda.Start(proceso)
}

func proceso(parametros Parametros) {
    cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
    if err != nil {
        log.Fatalf("unable to load SDK config, %v", err)
    }

    acusN32 := int32(parametros.Acus)

    svc := rds.NewFromConfig(cfg)

    // Configura el objeto rds.ModifyCurrentDBClusterCapacityInput
    var param rds.ModifyDBClusterInput
    param.ScalingConfiguration.MinCapacity = &acusN32
    param.DBClusterIdentifier = &parametros.Instancia

    /* resp, err := svc.ModifyCurrentDBClusterCapacity(context.TODO(), &param) */
    resp, err := svc.ModifyDBCluster(context.TODO(), &param)

    if err != nil {
        log.Fatalf("falló al modificar ACUS, %v", err)
    } else {
        log.Println("Los ACUS de " + *parametros.Instancia + " quedaron seteados en " + string(*resp.DBCluster.Capacity))
    }
}

错误出现在以下代码行:

var param rds.ModifyDBClusterInput
    param.ScalingConfiguration.MinCapacity = &acusN32
    param.DBClusterIdentifier = &parametros.Instancia

问题出在哪里?

&acusN32 是一个有效的 int32 指针。

英文:

We use this function in a AWS Lambda, but we're having the error of

> runtime error: invalid memory address or nil pointer dereference: errorString
> [{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/errors.go","line":39,"label":"lambdaPanicResponse"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/function.go","line":36,"label":"(Function).Invoke.func1"},{"path":"runtime/panic.go","line":679,"label":"gopanic"},{"path":"runtime/panic.go","line":199,"label":"panicmem"},{"path":"runtime/signal_unix.go","line":394,"label":"sigpanic"},{"path":"Lamda/main.go","line":55,"label":"HandlerAcus"},{"path":"reflect/value.go","line":460,"label":"Value.call"},{"path":"reflect/value.go","line":321,"label":"Value.Call"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/handler.go","line":124,"label":"NewHandler.func1"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/handler.go","line":24,"label":"lambdaHandler.Invoke"},{"path":"github.com/aws/aws-lambda-go@v1.24.0/lambda/function.go","line":64,"label":"(Function).Invoke"},{"path":"reflect/value.go","line":460,"label":"Value.call"},{"path":"reflect/value.go","line":321,"label":"Value.Call"},{"path":"net/rpc/server.go","line":377,"label":"(*service).call"},{"path":"runtime/asm_amd64.s","line":1357,"label":"goexit"}]

the code is

func main() {
	lambda.Start(proceso)
}

func proceso(parametros Parametros) {
	cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
	if err != nil {
		log.Fatalf("unable to load SDK config, %v", err)
	}

	acusN32 := int32(parametros.Acus)

	svc := rds.NewFromConfig(cfg)

	// Configura el objeto rds.ModifyCurrentDBClusterCapacityInput
	var param rds.ModifyDBClusterInput
	param.ScalingConfiguration.MinCapacity = &acusN32
	param.DBClusterIdentifier = &parametros.Instancia

	/* resp, err := svc.ModifyCurrentDBClusterCapacity(context.TODO(), &param) */
	resp, err := svc.ModifyDBCluster(context.TODO(),  &param)

	if err != nil {
		log.Fatalf("falló al modificar ACUS, %v", err)
	} else {
		log.Println("Los ACUS de " + *&parametros.Instancia + " quedaron seteados en " + string(*resp.DBCluster.Capacity))
	}
}

The line error is this

var param rds.ModifyDBClusterInput
	param.ScalingConfiguration.MinCapacity = &acusN32
	param.DBClusterIdentifier = &parametros.Instancia`

What's Wrong ?

&acusN32 is a valid int32 pointer

答案1

得分: 1

看起来在你的情况下,parametrosnil,所以你需要添加类似以下的代码:

func proceso(parametros Parametros) {
  if parametros == nil {
     // 记录错误并返回
  }
  ...
英文:

Looks like parametros is nil in you case, so you have to add something like this:

func proceso(parametros Parametros) {
  if parametros == nil {
     // log error & return
  }
  ...

huangapple
  • 本文由 发表于 2021年6月24日 04:24:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/68106647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定