Access Denied for ElasticBeanstalk DescribeConfigurationSettings API method

Viewed 206

I tried to run the DescribeConfigurationSettings API method for the ElasticBeanstalk as follow:

AWSElasticBeanstalk ebs = AWSElasticBeanstalkClientBuilder.standard().withRegion(Regions.EU_CENTRAL_1).withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
        for(ApplicationDescription ad : ebs.describeApplications().getApplications()){
            System.out.println(ad);
            for(EnvironmentDescription ed : ebs.describeEnvironments(new DescribeEnvironmentsRequest().withApplicationName(ad.getApplicationName())).getEnvironments()) {
                System.out.println(ebs.describeConfigurationSettings(new DescribeConfigurationSettingsRequest().withApplicationName(ad.getApplicationName()).withEnvironmentName(ed.getEnvironmentName())).getConfigurationSettings());

            }


        }

However, I got the exception of Access Denied with the following message:

Exception in thread "main" com.amazonaws.services.elasticbeanstalk.model.AWSElasticBeanstalkException: Access Denied: S3Bucket=elasticbeanstalk-env-resources-eu-central-1, S3Key=eb_patching_resources/instance_patch_extension.linux (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: NB44V0RXQG2WHH4T; Proxy: null) (Service: AWSElasticBeanstalk; Status Code: 400; Error Code: InvalidParameterValue; Request ID: b058aa54-fc9c-4879-9502-5cb5818bc64a; Proxy: null)

How can I resolve this issue?

2 Answers

Based on the error you get, it seems that you are missing some IAM permissions. I would start by adding AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy Managed policy to your user.

This policy is probably more permissive than what you actually need, but it would be difficult to pinpoint exactly, which permissions are necessary.

Amazon recommends using AWS SDK for Java V2.

Updated Code Here is the Java V2 code for this use case.

 package com.aws.example;

   import software.amazon.awssdk.regions.Region;
   import software.amazon.awssdk.services.elasticbeanstalk.ElasticBeanstalkClient;
   import software.amazon.awssdk.services.elasticbeanstalk.model.*;
   import java.util.List;

    public class DescribeApplications {

    public static void main(String[] args) {

        Region region = Region.US_EAST_1;
        ElasticBeanstalkClient beanstalkClient = ElasticBeanstalkClient.builder()
                .region(region)
                .build();

        DescribeApplicationsResponse applicationsResponse = beanstalkClient.describeApplications();
        List<ApplicationDescription> apps = applicationsResponse.applications();
        for (ApplicationDescription app: apps) {
            System.out.println("The application name is "+app.applicationName());
            DescribeEnvironmentsRequest desRequest =  DescribeEnvironmentsRequest.builder()
                            .applicationName(app.applicationName())
                            .build();


            DescribeEnvironmentsResponse res = beanstalkClient.describeEnvironments(desRequest) ;
            List<EnvironmentDescription> envDesc = res.environments();
            for (EnvironmentDescription desc: envDesc) {
                System.out.println("The Environment ARN is "+desc.environmentArn());
            }

        }
    }
  }

Output here:

enter image description here

Related