{"record":{"id":"ed6fb52ff5bb83a1","repo":"crowdsecurity/crowdsec","slug":"failed-to-load-aws-config-w","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/cloudwatch/run.go","lineNumber":81,"sourceCode":"\t\tregion = \"us-east-1\"\n\t}\n\n\tloadOpts = append(loadOpts, config.WithRegion(region))\n\n\tvar sharedConfigProfileNotExistError config.SharedConfigProfileNotExistError\n\n\tcfg, err := config.LoadDefaultConfig(ctx, loadOpts...)\n\tif errors.As(err, &sharedConfigProfileNotExistError) {\n\t\t// Fallback for tests/CI where the profile is not present\n\t\ts.logger.Debugf(\"shared config profile %q not found; retrying without profile\", aws.ToString(s.Config.AwsProfile))\n\t\tcfg, err = config.LoadDefaultConfig(ctx,\n\t\t\tconfig.WithRegion(region),\n\t\t\tconfig.WithCredentialsProvider(aws.AnonymousCredentials{}),\n\t\t)\n\t}\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load aws config: %w\", err)\n\t}\n\n\tvar clientOpts []func(*cloudwatchlogs.Options)\n\n\tif v := os.Getenv(\"AWS_ENDPOINT_FORCE\"); v != \"\" {\n\t\ts.logger.Debugf(\"[testing] overloading endpoint with %s\", v)\n\n\t\tclientOpts = append(clientOpts, func(o *cloudwatchlogs.Options) {\n\t\t\to.BaseEndpoint = aws.String(v)\n\t\t})\n\t}\n\n\ts.cwClient = cloudwatchlogs.NewFromConfig(cfg, clientOpts...)\n\n\treturn nil\n}\n\nfunc (s *Source) StreamingAcquisition(ctx context.Context, out chan pipeline.Event, t *tomb.Tomb) error {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/cloudwatch/run.go#L63-L99","documentation":"newClient loads the AWS SDK v2 config (config.LoadDefaultConfig) honoring region, profile and credentials chains. When that load fails — bad profile, missing credentials file, invalid configuration — the error is wrapped as `failed to load aws config: <err>`. No cloudwatch client can be created, so acquisition or one-shot collection stops.","triggerScenarios":"newClient called via ConfigureByDSN, Configure, or setupAWS when the AWS profile named in the DSN does not exist in ~/.aws/config, credentials files are malformed, or region configuration is invalid.","commonSituations":"`profile=prod` present in DSN but absent from ~/.aws/config; corrupted ~/.aws/credentials; AWS_CONFIG_FILE pointing to a missing file; invalid shared config YAML.","solutions":["Verify the profile exists: `aws configure list-profiles` and check ~/.aws/config and ~/.aws/credentials","Remove the `profile=` parameter from the DSN to use the default chain","Set AWS_REGION or add aws_region to the DSN and ensure credentials are resolvable (env vars, shared files, instance role)","Run `aws sts get-caller-identity --profile <name>` to validate the profile works with the AWS CLI"],"exampleFix":"// before\ncloudwatch://my-group?profile=nonexistent\n// after\ncloudwatch://my-group?profile=default&aws_region=us-east-1","handlingStrategy":"fallback","validationCode":"profiles, err := exec.Command(\"aws\", \"configure\", \"list-profiles\").Output()\nif err != nil || !strings.Contains(string(profiles), wantedProfile) {\n    return fmt.Errorf(\"AWS profile %q not found in shared config\", wantedProfile)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := newClient(ctx)\nif err != nil {\n    var credsErr error\n    if errors.As(err, &credsErr) { /* fall back to env credentials or default profile */ }\n    return err\n}","preventionTips":["Ensure ~/.aws/{config,credentials} exist and parse before deploying","Pin AWS_REGION or set aws_region in every DSN","Validate profiles with `aws sts get-caller-identity --profile X`","On EC2/ECS rely on instance roles instead of named profiles"],"tags":["aws","config","credentials","cloudwatch"],"backgroundTag":"missing-credentials","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"}