ozil
ozil

Reputation: 669

how to add api gateway ( with api key) to an exiting lambda cloudformation template?

I am learning SAM Cli and working with a existing template for a lambda function. I'm not 100% sure , if an API gateway is already created with this. but if not i want to extend this by adding an api gateway, with possibly authetication mechanism with an api key. also , I have created VPC with private/public subnets. how/where can i define those in this template. any code samples would be helpful.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sample SAM Template 

Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.8
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source:
          Properties:
            Path: /hello
            Method: get

Outputs:
 
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn

Upvotes: 0

Views: 838

Answers (1)

Marcin
Marcin

Reputation: 238249

You haven't provided any template code regarding the API geteway. Thus in general, if you want to use API key, you have to use three components in your template:

Upvotes: 1

Related Questions