# Define API with external openapi spec

**URL:** <https://forum.serverless.com/t/define-api-with-external-openapi-spec/11167>\
**Category:** Serverless Framework\
**Tags:** api-gateway, variables\
**Created:** [April 17, 2020, 7:12am UTC](https://forum.serverless.com/t/define-api-with-external-openapi-spec/11167 "2020-04-17T07:12:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gomesp](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gomesp/32/4148_2.png) [@gomesp](https://forum.serverless.com/u/gomesp)\
**Post date:** [April 17, 2020, 7:12am UTC](https://forum.serverless.com/t/define-api-with-external-openapi-spec/11167/1 "2020-04-17T07:12:22Z")

</div>

EDITED: See my response below for my progress. I only need to find out how to refer to a function ARN from an openApi spec declared in the resources block.

I’m trialing the `serverless.com` with AWS as the provider. I’d like to do a simple hello world app with API Gateway and Lambda, where I publish the API from an openapi spec.

I have seen in this [forum post](http://forum.serverless.com/t/reference-to-a-external-swagger-api-definition/5633) that I need to declare the spec as a resource in the serverless.yml file, but when doing so I get the following error when doing `sls deploy`:

I think I have mostly correct, except that in the openapi spec file I don’t know how to correctly refer to the URI for the API I am creating (as I am creating the lambda function within the same serverless project). Is that the reason I am getting the error?

```auto
  Serverless Error ---------------------------------------

  An error occurred: ApiGatewayRestApi - Errors found during import:
  	Unable to put integration on 'GET' for resource at path '/hello': Invalid function ARN or invalid uri (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: ...).

  Get Support --------------------------------------------
     Docs: docs.serverless.com
     Bugs: github.com/serverless/serverless/issues
     Issues: forum.serverless.com

  Your Environment Information ---------------------------
     Operating System: darwin
     Node Version: 12.16.2
     Framework Version: 1.67.3
     Plugin Version: 3.6.6
     SDK Version: 2.3.0
     Components Version: 2.29.3

```

I am trying the simplest example I can think of:

```auto
# serverless.yml
service: accounts-api

provider:
  name: aws
  apiName: accounts
  runtime: nodejs12.x
  stage: dev
  region: ap-southeast-2

functions:
  hello:
    handler: functions/handler.hello
    events:
      - http:
           path: /accounts
           method: GET

# The resources attribute will be sent directly to CloudFormation in raw format
resources:
    Resources:
      ApiGatewayRestApi:
        Type: 'AWS::ApiGateway::RestApi'
        Properties:
          Name: ${self:provider.apiName}-${self:provider.stage}
          Body:
            ${file(specs/simple-spec.yml)}
      ApiGatewayDeployment:
        Type: AWS::ApiGateway::Deployment
        Properties:
          RestApiId:
            Ref: ApiGatewayRestApi
          StageName: ${self:provider.stage}

```

and the openapi spec:

```auto
openapi: 3.0.0
info:
  version: 1.0.0
  title: Hello API
  description: Returns a hello world message
  
paths:
  /hello:
    get:
      description: Returns a hello world message              
      responses:
        '200':
          description: Successful response
      security:
      - api_key: []
      x-amazon-apigateway-auth:
        type: none          
      x-amazon-apigateway-integration:
         x-amazon-apigateway-integration:
         type: aws_proxy
         uri: arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:idAccount:function:hello/invocations
         httpMethod: GET
         passthroughBehavior: when_no_templates
         payloadFormatVersion: 1.0

```

---

<div class="post-metadata">

**Author:** ![gomesp](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gomesp/32/4148_2.png) [@gomesp](https://forum.serverless.com/u/gomesp)\
**Post date:** [April 17, 2020, 11:03am UTC](https://forum.serverless.com/t/define-api-with-external-openapi-spec/11167/2 "2020-04-17T11:03:18Z")

</div>

I realised that my uri under the `x-amazon-apigateway-integration:` attribute is not quite correct. I need to find the full ARN for the Lambda function that is created by this serverless project.

How can I dynamically refer to the lambda Arn in there? I am trying `${self:functions.hello.arn}` without any success. ☹

---

<div class="post-metadata">

**Author:** ![acxsjones](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/acxsjones/32/4683_2.png) [@acxsjones](https://forum.serverless.com/u/acxsjones)\
**Post date:** [September 6, 2020, 9:41pm UTC](https://forum.serverless.com/t/define-api-with-external-openapi-spec/11167/3 "2020-09-06T21:41:46Z")

</div>

Did you ever get this working.  
I would like to do interface first design with openapi 3.0 and user serverless
