Last active
April 6, 2020 20:26
-
-
Save Ghilteras/a501b7aa17ae93cfca83aac4be91ceed to your computer and use it in GitHub Desktop.
Localstack bug 2231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.amazonaws.client.builder.AwsClientBuilder; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.identitymanagement.AmazonIdentityManagement; | |
import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder; | |
import com.amazonaws.services.identitymanagement.model.CreateRoleRequest; | |
import com.amazonaws.services.identitymanagement.model.EntityAlreadyExistsException; | |
class Scratch { | |
public static void main(String[] args) { | |
AwsClientBuilder.EndpointConfiguration iamEndpoint = new AwsClientBuilder.EndpointConfiguration("http://localhost:4593", Regions.DEFAULT_REGION.getName()); | |
AmazonIdentityManagement localStackIAMClient = AmazonIdentityManagementClientBuilder.standard().withEndpointConfiguration(iamEndpoint).build(); | |
try { | |
String assume_policy_document = "" + | |
" {\n" + | |
" 'Version': '2012-10-17',\n" + | |
" 'Statement': [\n" + | |
" {\n" + | |
" 'Action': 'sts:AssumeRole',\n" + | |
" 'Principal': {'Service': 'lambda.amazonaws.com'}\n" + | |
" }\n" + | |
" ]\n" + | |
" }"; | |
CreateRoleRequest createRoleRequest = new CreateRoleRequest().withRoleName("foo").withAssumeRolePolicyDocument(assume_policy_document); | |
localStackIAMClient.createRole(createRoleRequest); | |
localStackIAMClient.createRole(createRoleRequest); | |
} catch (EntityAlreadyExistsException e) { | |
// AmazonIdentityManagementException with null is thrown instead | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment