Skip to content

Instantly share code, notes, and snippets.

@y16ra
Created July 6, 2018 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y16ra/076e340ef4dac375b0d59bf65472e8f7 to your computer and use it in GitHub Desktop.
Save y16ra/076e340ef4dac375b0d59bf65472e8f7 to your computer and use it in GitHub Desktop.
Call AWS Lambda Function by Kotlin
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()))
}
}
@y16ra
Copy link
Author

y16ra commented Jul 6, 2018

dependencies {
    compile 'com.amazonaws:aws-java-sdk:1.11.360'
}

@y16ra
Copy link
Author

y16ra commented Jul 6, 2018

@Li-Fengxin
Copy link

Thank you,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment