I implemented AWS lambda method to learn what I can do with it. What I have now:
- AWS lambda itself
- API Gateway
- Amazon CloudWatch Logs
In API Gateway configs I see next options:
- Endpoint: https://xyz.execute-api.us-east-2.amazonaws.com/dummy/test-store
- API key: QW123E45RTY6
- Authorization: NONE
Behind this lambda I have Java code, implementing com.amazonaws.services.lambda.runtime.RequestStreamHandler and a REST controller behind it, something like that:
@Path("/tester")
public class TestResource {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private TestRepository testRepository;
public void setTestRepository(TestRepository testRepository) {
this.testRepository = testRepository;
}
@POST
@Path("/{identifier}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.WILDCARD)
public Response store(@PathParam("identifier") String identifier, @QueryParam("hashcode") String hashcode) {
try {
this.testRepository.store(identifier, hashcode);
} catch (RuntimeException ex) {
LOG.error("Failed to store pair {}, {}", identifier, hashcode, ex);
throw new InternalServerErrorException(ex);
}
return Response.noContent().build();
}
}
Now I tried invoking this service through Postman:
Option 1 - Invoke what I saw in API Gateway:
- URL: https://xyz.execute-api.us-east-2.amazonaws.com/dummy/test-store
- Method: POST
- Headers:
- Key: x-api-key
- Value: QW123E45RTY6
Result: 404 Not Found, see the appropriate logs in AWS CloudWatch.
Option 2 - Invoke my method:
- URL: https://xyz.execute-api.us-east-2.amazonaws.com/dummy/test-store/tester/qwerty123
- Method: POST
- Headers:
- Key: x-api-key
- Value: QW123E45RTY6
Result: 403 Forbidden, no logs in AWS CloudWatch.
{
"message": "Missing Authentication Token"
}
I fully understand why Option 1 did not work, but what went wrong with Option 2? Could you please help me understanding what I missed?