本文整理汇总了Java中com.amazonaws.services.lambda.AWSLambda类的典型用法代码示例。如果您正苦于以下问题:Java AWSLambda类的具体用法?Java AWSLambda怎么用?Java AWSLambda使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AWSLambda类属于com.amazonaws.services.lambda包,在下文中一共展示了AWSLambda类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeLambda
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
public static void invokeLambda(String function, Object payload, boolean async) {
String payloadString = GSON.toJson(payload);
AWSLambda lambda = AWSLambdaProvider.getLambdaClient();
InvokeRequest request = new InvokeRequest()
.withFunctionName(function)
.withInvocationType(async ? InvocationType.Event : InvocationType.RequestResponse)
.withPayload(payloadString);
lambda.invoke(request);
}
示例2: addPermission
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
private boolean addPermission(String apiId, String region, String accountNumber, String serviceArn, String serviceName, AWSLambda lambdaClient, String permString)
{
boolean ret = false;
if ( ! permString.startsWith("/"))
permString = "/" + permString;
getLog().info("Adding permission to lambda: " + permString);
AddPermissionRequest apReq = new AddPermissionRequest()
.withFunctionName(serviceName)
.withAction("lambda:InvokeFunction")
.withSourceArn("arn:aws:execute-api:" + region + ":" + accountNumber + ":" + apiId + permString)
.withPrincipal("apigateway.amazonaws.com")
.withStatementId(UUID.randomUUID().toString());
// Now update the permissions
AddPermissionResult apRes = lambdaClient.addPermission(apReq);
getLog().info("Statement: " + apRes.getStatement());
ret = apRes.getSdkHttpMetadata().getHttpStatusCode() == 201;
getLog().info("Status: " + apRes.getSdkHttpMetadata().getHttpStatusCode());
return ret;
}
示例3: FeignLambdaServiceInvokerClient
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
FeignLambdaServiceInvokerClient(LambdaInvokerFactory.Builder builder, AWSLambda awsLambdaClient,
String functionName, String functionAlias, String functionVersion) {
requireNonNull(awsLambdaClient);
requireNonNull(functionName);
service = builder
.lambdaFunctionNameResolver((method, annotation, config) -> functionName)
.functionAlias(functionAlias)
.functionVersion(functionVersion)
.lambdaClient(awsLambdaClient)
.build(LambdaInvokerService.class);
}
示例4: CreateCloudFrontSecurityGroupUpdaterLambdaOperation
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
@Inject
public CreateCloudFrontSecurityGroupUpdaterLambdaOperation(final CloudFormationService cloudFormationService,
final EnvironmentMetadata environmentMetadata,
@Named(CF_OBJECT_MAPPER) final ObjectMapper cloudformationObjectMapper,
AWSLambda awsLambda,
AmazonS3 amazonS3) {
this.cloudFormationService = cloudFormationService;
this.cloudformationObjectMapper = cloudformationObjectMapper;
this.environmentMetadata = environmentMetadata;
this.awsLambda = awsLambda;
this.amazonS3 = amazonS3;
final Region region = Region.getRegion(Regions.US_EAST_1);
AmazonCloudFormation amazonCloudFormation = new AmazonCloudFormationClient();
amazonCloudFormation.setRegion(region);
amazonSNS = new AmazonSNSClient();
amazonSNS.setRegion(region);
}
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:20,代码来源:CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java
示例5: deploy
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
void deploy(AwsKeyPair keyPair, String region, String zipFilename, String functionName, Proxy proxy) {
long t = System.currentTimeMillis();
final AWSCredentialsProvider credentials = new AWSStaticCredentialsProvider(
new BasicAWSCredentials(keyPair.key, keyPair.secret));
AWSLambda lambda = AWSLambdaClientBuilder.standard().withCredentials(credentials)
.withClientConfiguration(Util.createConfiguration(proxy)).withRegion(region).build();
byte[] bytes;
try {
bytes = IOUtils.toByteArray(new FileInputStream(zipFilename));
} catch (IOException e) {
throw new RuntimeException(e);
}
DecimalFormat df = new DecimalFormat("0.000");
log.info("deploying " + zipFilename + ", length=" + df.format(bytes.length / 1024.0 / 1024.0)
+ "MB, to functionName=" + functionName);
lambda.updateFunctionCode( //
new UpdateFunctionCodeRequest() //
.withFunctionName(functionName) //
.withPublish(true) //
.withZipFile(ByteBuffer.wrap(bytes)));
log.info("deployed in " + (System.currentTimeMillis() - t) + "ms");
}
示例6: getLambdaClient
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
public static AWSLambda getLambdaClient() {
String smr_stage = System.getenv().get("SMR_STAGE");
if (smr_stage.equals("DEV"))
return FakeAWSLambdaHolder.LAMBDA_CLIENT;
else
return AWSLambdaHolder.LAMBDA_CLIENT;
}
示例7: lambdaSingletonTest
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
@Test
public void lambdaSingletonTest() throws Exception {
AWSLambda firstInstance = AWSLambdaProvider.getLambdaClient();
AWSLambda secondInstance = AWSLambdaProvider.getLambdaClient();
assertTrue(firstInstance == secondInstance);
}
示例8: testLambdaInvokeSubsegmentContainsFunctionName
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
@Test
public void testLambdaInvokeSubsegmentContainsFunctionName() {
// Setup test
AWSLambda lambda = AWSLambdaClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();
AmazonHttpClient amazonHttpClient = new AmazonHttpClient(new ClientConfiguration());
ConnectionManagerAwareHttpClient apacheHttpClient = Mockito.mock(ConnectionManagerAwareHttpClient.class);
HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
BasicHttpEntity responseBody = new BasicHttpEntity();
responseBody.setContent(new ByteArrayInputStream("null".getBytes(StandardCharsets.UTF_8))); // Lambda returns "null" on successful fn. with no return value
httpResponse.setEntity(responseBody);
try {
Mockito.doReturn(httpResponse).when(apacheHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(HttpContext.class));
} catch (IOException e) { }
Whitebox.setInternalState(amazonHttpClient, "httpClient", apacheHttpClient);
Whitebox.setInternalState(lambda, "client", amazonHttpClient);
// Test logic
Segment segment = AWSXRay.beginSegment("test");
InvokeRequest request = new InvokeRequest();
request.setFunctionName("testFunctionName");
InvokeResult r = lambda.invoke(request);
System.out.println(r.getStatusCode());
System.out.println(r);
Assert.assertEquals(1, segment.getSubsegments().size());
Assert.assertEquals("Invoke", segment.getSubsegments().get(0).getAws().get("operation"));
System.out.println(segment.getSubsegments().get(0).getAws());
Assert.assertEquals("testFunctionName", segment.getSubsegments().get(0).getAws().get("function_name"));
}
示例9: resolveAwsLambdaClient
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
protected AWSLambda resolveAwsLambdaClient() {
AWSLambda resolvedClient = awsLambdaClient;
if (resolvedClient == null && region != null) {
resolvedClient = AWSLambdaClientBuilder.standard().withRegion(region).build();
}
return requireToBuild(resolvedClient, "an awsLambdaClient or a region is required");
}
示例10: setFunctionName_LambdaClientGiven_ShouldUseLambdaClient
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
@Test
public void setFunctionName_LambdaClientGiven_ShouldUseLambdaClient() {
AWSLambda myLambdaClient = mock(AWSLambda.class);
builder.setFunctionName(FUNCTION_NAME);
builder.setAwsLambdaClient(myLambdaClient);
builder.build();
verify(builder).create(myLambdaClient, FUNCTION_NAME, null, null);
}
示例11: setFunctionName_LambdaClientAndRegionGiven_ShouldUseLambdaClient
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
@Test
public void setFunctionName_LambdaClientAndRegionGiven_ShouldUseLambdaClient() {
AWSLambda myLambdaClient = mock(AWSLambda.class);
builder.setFunctionName(FUNCTION_NAME);
builder.setRegion(Regions.AP_NORTHEAST_1);
builder.setAwsLambdaClient(myLambdaClient);
builder.build();
verify(builder).create(myLambdaClient, FUNCTION_NAME, null, null);
}
示例12: init_LambdaClientGiven_ShouldUseOnInvocationBuilder
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
@Test
public void init_LambdaClientGiven_ShouldUseOnInvocationBuilder() {
AWSLambda myLambdaClient = mock(AWSLambda.class);
FeignLambdaServiceInvokerClient invokerClient = init(myLambdaClient, FUNCTION_NAME, null, null);
verify(lambdaInvokerFactoryBuilder).lambdaClient(myLambdaClient);
verify(lambdaInvokerFactoryBuilder).lambdaFunctionNameResolver(eqFn(FUNCTION_NAME));
verify(lambdaInvokerFactoryBuilder).functionAlias(isNull());
verify(lambdaInvokerFactoryBuilder).functionVersion(isNull());
verify(lambdaInvokerFactoryBuilder).build(LambdaInvokerService.class);
assertEquals(service, invokerClient.getInvokerService());
}
示例13: authenticate
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
/**
* Looks up the assigned role for the running Lambda via the GetFunctionConfiguration API. Requests a token from
* Cerberus and attempts to decrypt it as that role.
*/
@Override
protected void authenticate() {
final Region currentRegion = RegionUtils.getRegion(this.region);
final AWSLambda lambdaClient = new AWSLambdaClient();
lambdaClient.setRegion(currentRegion);
final GetFunctionConfigurationResult functionConfiguration = lambdaClient.getFunctionConfiguration(
new GetFunctionConfigurationRequest()
.withFunctionName(functionName)
.withQualifier(qualifier));
final String roleArn = functionConfiguration.getRole();
if (StringUtils.isBlank(roleArn)) {
throw new IllegalStateException("Lambda function has no assigned role, aborting Cerberus authentication.");
}
final Matcher roleArnMatcher = IAM_ROLE_ARN_PATTERN.matcher(roleArn);
if (!roleArnMatcher.matches()) {
throw new IllegalStateException("Lambda function assigned role is not a valid IAM role ARN.");
}
try {
getAndSetToken(roleArn, currentRegion);
return;
} catch (AmazonClientException ace) {
LOGGER.warn("Unexpected error communicating with AWS services.", ace);
} catch (JsonSyntaxException jse) {
LOGGER.error("The decrypted auth response was not in the expected format!", jse);
} catch (VaultClientException sce) {
LOGGER.warn("Unable to acquire Vault token for IAM role: " + roleArn, sce);
}
throw new VaultClientException("Unable to acquire token with Lambda instance role.");
}
示例14: configure
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
/**
* Binds all the Amazon services used.
*/
@Override
protected void configure() {
final Region region = Region.getRegion(Regions.fromName(regionName));
bind(AmazonEC2.class).toInstance(createAmazonClientInstance(AmazonEC2Client.class, region));
bind(AmazonCloudFormation.class).toInstance(createAmazonClientInstance(AmazonCloudFormationClient.class, region));
bind(AmazonIdentityManagement.class).toInstance(createAmazonClientInstance(AmazonIdentityManagementClient.class, region));
bind(AWSKMS.class).toInstance(createAmazonClientInstance(AWSKMSClient.class, region));
bind(AmazonS3.class).toInstance(createAmazonClientInstance(AmazonS3Client.class, region));
bind(AmazonAutoScaling.class).toInstance(createAmazonClientInstance(AmazonAutoScalingClient.class, region));
bind(AWSSecurityTokenService.class).toInstance(createAmazonClientInstance(AWSSecurityTokenServiceClient.class, region));
bind(AWSLambda.class).toInstance(createAmazonClientInstance(AWSLambdaClient.class, region));
bind(AmazonSNS.class).toInstance(createAmazonClientInstance(AmazonSNSClient.class, region));
}
示例15: getLambdaClient
import com.amazonaws.services.lambda.AWSLambda; //导入依赖的package包/类
protected AWSLambda getLambdaClient() {
if (lambdaClient != null) {
return lambdaClient;
}
return lambdaClient = new AWSLambdaClient(getAWSCredentialsProvideChain()).withRegion(Region.getRegion(Regions.fromName(deployment.getRegion())));
}