{"record":{"id":"06b193f53b8f923b","repo":"crowdsecurity/crowdsec","slug":"failed-to-load-aws-config-w-06b193","errorCode":null,"errorMessage":"failed to load aws config: %w","messagePattern":"failed to load aws config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/s3/config.go","lineNumber":63,"sourceCode":"\tvar loadOpts []func(*config.LoadOptions) error\n\tif s.Config.AwsProfile != nil && *s.Config.AwsProfile != \"\" {\n\t\tloadOpts = append(loadOpts, config.WithSharedConfigProfile(*s.Config.AwsProfile))\n\t}\n\n\tregion := s.Config.AwsRegion\n\tif region == \"\" {\n\t\tregion = \"us-east-1\"\n\t}\n\n\tloadOpts = append(loadOpts, config.WithRegion(region))\n\n\tif c := defaultCreds(); c != nil {\n\t\tloadOpts = append(loadOpts, config.WithCredentialsProvider(c))\n\t}\n\n\tcfg, err := config.LoadDefaultConfig(ctx, loadOpts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load aws config: %w\", err)\n\t}\n\n\tvar clientOpts []func(*s3.Options)\n\tif s.Config.AwsEndpoint != \"\" {\n\t\tclientOpts = append(clientOpts, func(o *s3.Options) {\n\t\t\to.BaseEndpoint = aws.String(s.Config.AwsEndpoint)\n\t\t})\n\t}\n\n\treturn s3.NewFromConfig(cfg, clientOpts...), nil\n}\n\nfunc (s *Source) newSQSClient(ctx context.Context) (*sqs.Client, error) {\n\tvar loadOpts []func(*config.LoadOptions) error\n\tif s.Config.AwsProfile != nil && *s.Config.AwsProfile != \"\" {\n\t\tloadOpts = append(loadOpts, config.WithSharedConfigProfile(*s.Config.AwsProfile))\n\t}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/s3/config.go#L45-L81","documentation":"newS3Client builds the AWS SDK (go v2) shared configuration via config.LoadDefaultConfig for the S3 client. The SDK errors when the resolved configuration is invalid (unparseable config files, bad profile, invalid region format), and the source wraps it as 'failed to load aws config'.","triggerScenarios":"Configure or ConfigureByDSN when ~/.aws/config or ~/.aws/credentials is malformed, AWS_PROFILE names a missing profile, the region value is unparseable, or AWS_CONFIG_FILE/AWS_SHARED_CREDENTIALS_FILE point to invalid files.","commonSituations":"Hand-edited ~/.aws files with duplicate or malformed keys; AWS_PROFILE pointing at a profile that no longer exists; empty/invalid region entries; stale env vars in the service environment.","solutions":["Validate the environment with the AWS CLI: AWS_PROFILE=<profile> aws s3 ls (or `aws configure list`)","Fix region/profile entries in ~/.aws/config, or set AWS_REGION/AWS_DEFAULT_REGION explicitly","Repair or remove malformed entries in ~/.aws/config and ~/.aws/credentials","Check AWS_CONFIG_FILE / AWS_SHARED_CREDENTIALS_FILE point to readable, well-formed files"],"exampleFix":"// before (~/.aws/config)\n[default]\nregion =\n// after\n[default]\nregion = us-east-1","handlingStrategy":"validation","validationCode":"if os.Getenv(\"AWS_REGION\") == \"\" && os.Getenv(\"AWS_DEFAULT_REGION\") == \"\" {\n    // ensure ~/.aws/config defines a region for the active profile\n}\nif p := os.Getenv(\"AWS_PROFILE\"); p != \"\" {\n    if _, err := os.Stat(os.Getenv(\"AWS_CONFIG_FILE\")); err != nil {\n        // config file missing — fail fast before LoadDefaultConfig\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate credentials/config with the AWS CLI before deployment","Set AWS_REGION explicitly in the service environment","Keep ~/.aws files minimal, well-formed, and consistent profile names","Smoke-test config.LoadDefaultConfig in CI"],"tags":["aws","s3","config"],"backgroundTag":"invalid-config-value","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}