英文:
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 = ¶metros.Instancia
/* resp, err := svc.ModifyCurrentDBClusterCapacity(context.TODO(), ¶m) */
resp, err := svc.ModifyDBCluster(context.TODO(), ¶m)
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 = ¶metros.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
看起来在你的情况下,parametros
是 nil
,所以你需要添加类似以下的代码:
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
}
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论