Closed nelsonic closed 8 years ago
@nelsonic I think we need to either re-configure the security of the API endpoint or we need to make the secret key available to anyone who wants to use it.
Permission Model: http://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html API Keys: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-api-keys.html
test api key: LhGU6jr5C19QrT8yexCNoaBYeYHy9iwa5ugZlRzm
(don't worry, I will change this...)
so we can run the following cURL
command in terminal:
curl --header "x-api-key: LhGU6jr5C19QrT8yexCNoaBYeYHy9iwa5ugZlRzm" https://r09u5uw11g.execute-api.eu-west-1.amazonaws.com/prod/Concatenate
@nelsonic I was just looking at the permissions model docs in the API Gateway http://docs.aws.amazon.com/apigateway/latest/developerguide/permissions.html Can you set up the access policy from either Lambda or API Gateway?
Save
button:
LambdaMicroservice
and the stage is prod
) then click the Add
button:
You should now see that the API Key is Enabled for your prod
stage:
Concatenate
Lambda function you created earlier.
cURL
Command in your terminal to access the endpoint:curl --header "x-api-key: LhGU6jr5C19QrT8yexCNoaBYeYHy9iwa5ugZlRzm" https://r09u5uw11g.execute-api.eu-west-1.amazonaws.com/prod/Concatenate
Note: I slightly modified my Lambda function to return a timestamp so I know when the funciton gets executed:
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
console.log('context:', JSON.stringify(context, null, 2));
event.key1 = event.key1 || 'Hello'; // set default values
event.key2 = event.key1 || 'World!';
console.log('value1 =', event.key1);
console.log('value2 =', event.key2);
var date = new Date();
var time = date.toString();
context.succeed(event.key1 + ' ' + event.key2 + ' >> ' + time );
};
For even more steps on enabling API Keys on AWS API Gateway, see: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-api-keys.html
When attempting to access the lambda function using the url: https://r09u5uw11g.execute-api.eu-west-1.amazonaws.com/prod/Concatenate We get:
What do w need to do to make this publicly accessible?