1

我想通过 Lambda 中的 AWS Security Token Service 获取临时凭证,但它总是超时AWSSecurityTokenServiceClientBuilder.standard().build()

有人帮助我吗?

源代码:

package example;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder;
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest;
import com.amazonaws.services.securitytoken.model.AssumeRoleResult;

public class SecurityTokenService implements RequestHandler<Request, Credential> {

    public Credential handleRequest(Request request, Context context) {
        AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest()
                .withPolicy("arn:aws:iam::12345678900:policy/SomePolicy")
                .withDurationSeconds(900);

        AWSSecurityTokenService securityTokenService = AWSSecurityTokenServiceClientBuilder.standard().build();

        AssumeRoleResult assumeRoleResult = securityTokenService.assumeRole(assumeRoleRequest);

        return new Credential(assumeRoleResult.getCredentials());

    }

}

错误信息:

{
  "errorMessage": "2018-02-22T09:12:55.102Z 8f49ee0a-17b0-11e8-892f-753d21bb516c Task timed out after 3.00 seconds"
}
4

0 回答 0