Created
July 6, 2018 03:46
-
-
Save y16ra/076e340ef4dac375b0d59bf65472e8f7 to your computer and use it in GitHub Desktop.
Call AWS Lambda Function by Kotlin
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
class AwsLambdaClient { | |
val aws_access_key_id = "<YOUR_ACCESS_KEY_PASTE_HERE>" | |
val aws_secret_access_key = "<YOUR_SECRET_KEY_PASTE_HERE>" | |
val region = "ap-northeast-1" | |
val function_name = "test_func" | |
fun invoke() { | |
val payload = """ | |
{ | |
"token": "TOKEN", | |
"client_id": "'CLIENT_ID'" | |
} | |
""".trimIndent() | |
println(payload) | |
val cp = AWSStaticCredentialsProvider( | |
BasicAWSCredentials(aws_access_key_id, aws_secret_access_key)) | |
val client = AWSLambdaClientBuilder.standard() | |
.withCredentials(cp).withRegion(region).build() | |
// call lambda function | |
val res = client.invoke(InvokeRequest() | |
.withFunctionName(function_name) | |
.withInvocationType(InvocationType.RequestResponse) | |
.withPayload(payload)) | |
// result | |
println(res.statusCode) | |
println(String(res.payload.array())) | |
} | |
} |
Author
y16ra
commented
Jul 6, 2018
Use AWS SDK for Java
https://aws.amazon.com/jp/developers/getting-started/java/
Thank you,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment