By continuing you indicate that you have read and agree to our Terms of service and Privacy policy
by aws Python Version: v1.72.0 License: Apache-2.0
by aws Python Version: v1.72.0 License: Apache-2.0
Support
Quality
Security
License
Reuse
kandi has reviewed aws-sam-cli and discovered the below as its top functions. This is intended to give you an instant insight into aws-sam-cli implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
See all related Code Snippets
QUESTION
Python/Docker ImportError: cannot import name 'json' from itsdangerous
Asked 2022-Mar-31 at 12:49I am trying to get a Flask and Docker application to work but when I try and run it using my docker-compose up
command in my Visual Studio terminal, it gives me an ImportError called ImportError: cannot import name 'json' from itsdangerous
. I have tried to look for possible solutions to this problem but as of right now there are not many on here or anywhere else. The only two solutions I could find are to change the current installation of MarkupSafe and itsdangerous to a higher version: https://serverfault.com/questions/1094062/from-itsdangerous-import-json-as-json-importerror-cannot-import-name-json-fr and another one on GitHub that tells me to essentially change the MarkUpSafe and itsdangerous installation again https://github.com/aws/aws-sam-cli/issues/3661, I have also tried to make a virtual environment named veganetworkscriptenv
to install the packages but that has also failed as well. I am currently using Flask 2.0.0 and Docker 5.0.0 and the error occurs on line eight in vegamain.py.
Here is the full ImportError that I get when I try and run the program:
veganetworkscript-backend-1 | Traceback (most recent call last):
veganetworkscript-backend-1 | File "/app/vegamain.py", line 8, in <module>
veganetworkscript-backend-1 | from flask import Flask
veganetworkscript-backend-1 | File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
veganetworkscript-backend-1 | from . import json
veganetworkscript-backend-1 | File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
veganetworkscript-backend-1 | from itsdangerous import json as _json
veganetworkscript-backend-1 | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
veganetworkscript-backend-1 exited with code 1
Here are my requirements.txt, vegamain.py, Dockerfile, and docker-compose.yml files:
requirements.txt:
Flask==2.0.0
Flask-SQLAlchemy==2.4.4
SQLAlchemy==1.3.20
Flask-Migrate==2.5.3
Flask-Script==2.0.6
Flask-Cors==3.0.9
requests==2.25.0
mysqlclient==2.0.1
pika==1.1.0
wolframalpha==4.3.0
vegamain.py:
# Veganetwork (C) TetraSystemSolutions 2022
# all rights are reserved.
#
# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
#
# get our imports in order first
from flask import Flask # <-- error occurs here!!!
# start the application through flask.
app = Flask(__name__)
# if set to true will return only a "Hello World" string.
Debug = True
# start a route to the index part of the app in flask.
@app.route('/')
def index():
if (Debug == True):
return 'Hello World!'
else:
pass
# start the flask app here --->
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Dockerfile:
FROM python:3.9
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app
docker-compose.yml:
version: '3.8'
services:
backend:
build:
context: .
dockerfile: Dockerfile
command: 'python vegamain.py'
ports:
- 8004:5000
volumes:
- .:/app
depends_on:
- db
# queue:
# build:
# context: .
# dockerfile: Dockerfile
# command: 'python -u consumer.py'
# depends_on:
# - db
db:
image: mysql:5.7.22
restart: always
environment:
MYSQL_DATABASE: admin
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33069:3306
How exactly can I fix this code? thank you!
ANSWER
Answered 2022-Feb-20 at 12:31I was facing the same issue while running docker containers with flask.
I downgraded Flask
to 1.1.4
and markupsafe
to 2.0.1
which solved my issue.
Check this for reference.
QUESTION
Is there a way to incrementally build container images with AWS SAM?
Asked 2022-Mar-27 at 16:53I have created a Lambda function using AWS SAM CLI which is deployed as a container image. Problem is the requirements are downloaded every time I make a small change in the code(app.py) and run sam build. The reason can be undestood from the Dockerfile below.
Dockerfile
FROM public.ecr.aws/lambda/python:3.8
COPY app.py requirements.txt ./
COPY models /opt/ml/models
RUN python3.8 -m pip install -r requirements.txt -t .
CMD ["app.lambda_handler"]
It downloads the requirements every time I run sam build.
I also came across a thread on github to use --cached option but it is not working if we use container image. https://github.com/aws/aws-sam-cli/issues/805
template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 50
MemorySize: 5000
Resources:
InferenceFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
PackageType: Image
Architectures:
- x86_64
Metadata:
Dockerfile: Dockerfile
DockerContext: ./app
DockerTag: python3.8-v1
The dependency is tensorflow 2.8.0 which is over 200MB and I cannot change to any other options like tensorflow-lite.
ANSWER
Answered 2022-Mar-27 at 16:53With the way docker caching works, everything after your COPY
statements is invalidated in cache (assuming changing). The way dependencies are often retained in cache is by only adding what is necessary to install dependencies, installing them, and then only adding your service code once dependencies are installed. In the example below, the pip install
will only run more than once if requirements.txt changes.
FROM public.ecr.aws/lambda/python:3.8
COPY requirements.txt ./
RUN python3.8 -m pip install -r requirements.txt -t .
COPY app.py ./
COPY models /opt/ml/models
CMD ["app.lambda_handler"]
QUESTION
How to change MarkUpSafe version in virtual environment?
Asked 2022-Feb-26 at 04:28I am trying to make an application using python and gRPC as shown in this article - link
I am able to run the app successfully on my terminal but to run with a frontend I need to run it as a flask app, codebase. And I am doing all this in a virtual environment.
when I run my flask command FLASK_APP=marketplace.py flask run
This is the error I get
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/Users/alex/Desktop/coding/virt/lib/python3.8/site-packages/markupsafe/__init__.py)
On researching about this error I found this link - it basically tells us that currently I am using a higher version of MarkUpSafe library than required.
So I did pip freeze --local
inside the virtualenv and got MarkUpSafe version to be MarkupSafe==2.1.0
I think if I change the version of this library from 2.1.0 to 2.0.1 then the flask app might run.
How can I change this library's version from the terminal?
PS: If you think changing the version of the library won't help in running the flask app, please let me know what else can I try in this.
ANSWER
Answered 2022-Feb-26 at 04:28If downgrading will solve the issue for you try the following code inside your virtual environment.
pip install MarkupSafe==2.0.1
QUESTION
Build and deploy AWS Lambda of type image using SAM in Gitlab runner
Asked 2021-Dec-30 at 18:15I'm trying to set up CI/CD for an AWS Lambda using the SAM cli tool inside a Gitlab runner.
My Lambda function is a Go app shipped as a container image.
I followed this article to set it up properly: https://aws.amazon.com/blogs/apn/using-gitlab-ci-cd-pipeline-to-deploy-aws-sam-applications/
Unfortunately, the used .gitlab-ci.yml
seems to be only applicable to functions of PackageType
Zip
, i.e. by uploading the application code to an S3 bucket:
image: python:3.8
stages:
- deploy
production:
stage: deploy
before_script:
- pip3 install awscli --upgrade
- pip3 install aws-sam-cli --upgrade
script:
- sam build
- sam package --output-template-file packaged.yaml --s3-bucket #S3Bucket#
- sam deploy --template-file packaged.yaml --stack-name gitlab-example --s3-bucket #S3Bucket# --capabilities CAPABILITY_IAM --region us-east-1
environment: production
I adjusted the script to these lines:
script:
- sam build
- sam deploy
sam build
fails at this stage:
Building codeuri: /builds/user/app runtime: None metadata: {'DockerTag': 'go1.x-v1', 'DockerContext': '/builds/user/app/hello-world', 'Dockerfile': 'Dockerfile'} architecture: x86_64 functions: ['HelloWorldFunction']
Building image for HelloWorldFunction function
Build Failed
Error: Building image for HelloWorldFunction requires Docker. is Docker running?
This guide at Gitlab suggests using image: docker
with dind
enabled, so I tried this config:
image: docker
services:
- docker:dind
stages:
- deploy
production:
stage: deploy
before_script:
- pip3 install awscli --upgrade
- pip3 install aws-sam-cli --upgrade
script:
- sam build
- sam deploy
environment: production
This in turn fails because the base docker
image does not ship Python. How can I combine those two approaches to have Docker and SAM available at the same time?
ANSWER
Answered 2021-Dec-30 at 18:15You can:
docker
image and install python in your job ORpython
image and install docker in your job ORimage:
.Installing python in the docker image:
production:
image: docker
stage: deploy
before_script:
- apk add --update python3 py3-pip
- pip3 install awscli --upgrade
- pip3 install aws-sam-cli --upgrade
script:
- sam build
- sam deploy
environment: production
Installing docker in the Python image:
production:
image: python:3.9-slim
stage: deploy
before_script:
- apt update && apt install -y --no-install-recommends docker.io
- pip3 install awscli --upgrade
- pip3 install aws-sam-cli --upgrade
script:
- sam build
- sam deploy
environment: production
Or build your own image:
FROM python:3.9-slim
RUN apt update && apt install -y --no-install-recommends docker.io
docker build -t myregistry.example.com/myrepo/myimage:latest
docker push myregistry.example.com/myrepo/myimage:latest
production:
image: myregistry.example.com/myrepo/myimage:latest
# ...
QUESTION
How do I install a specific version of python on alpine linux (python3.8)?
Asked 2021-Dec-28 at 21:23Currently I'm using a dind configuration in gitlab
This dind works for me to deploy a dockerized lambda function through SAM.
This is my before script
- apk add --no-cache curl jq
- apk add --no-cache python3 python3-dev py3-setuptools
- apk add py3-pip
- apk add --no-cache build-base g++ make cmake unzip curl-dev
- apk add --no-cache autoconf automake libtool libexecinfo-dev
- apk add --no-cache git
- pip3 install --no-cache --upgrade wheel
- pip3 install awscli --upgrade
- pip3 install aws-sam-cli --upgrade
I'm having troubles because the lambda function python version is 3.8 an sam builds
complains that the version the docker gitlab setup is different and doesn't find 3.8
ANSWER
Answered 2021-Dec-28 at 21:23Finally I solve it Probably I lacked context I'm doing a gitlab.yaml file to build, test and deploy my application in AWS thorugh SAM.
Since one of my lambda functions is a dockerized lambda function I nee sam to be able to access docker
as a command so it can run docker pull
and docker build
The other lambda functions that I have use python3.8 as runtime so the docker version I was using as a base image pointed to https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/
so everyt time something was installed with apk
the version was 3.15 which has python3.10.
A solution to this is use:
image: docker:19.03.15-alpine3.13
as a base image with the service dind like this:
image: docker:19.03.15-alpine3.13
## This will run a Docker daemon in a container (Docker-In-Docker), which will
## be available at thedockerhost:2375. If you make e.g. port 5000 public in Docker
## (`docker run -p 5000:5000 yourimage`) it will be exposed at thedockerhost:5000.
services:
- name: docker:dind
alias: thedockerhost
variables:
# Tell docker CLI how to talk to Docker daemon; see
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor
DOCKER_HOST: tcp://thedockerhost:2375/
# DOCKER_HOST: tcp://docker:2375/
# Use the overlays driver for improved performance:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
REPOSITORY_URL: ######.dkr.ecr.region.amazonaws.com/
REGION: us-east-2
deploy:
stage: deploy
before_script:
- apk add --no-cache python3
- apk add --no-cache curl jq
- apk add --no-cache python3-dev py3-setuptools
- apk add --no-cache py3-pip
- apk add --no-cache py-pip
- apk add --no-cache build-base g++ make cmake unzip curl-dev
- apk add --no-cache autoconf automake libtool libexecinfo-dev
- apk add --no-cache git
- pip3 install --no-cache --upgrade wheel
- pip3 install --no-cache awscli --upgrade
- pip3 install --no-cache aws-sam-cli --upgrade
script:
- aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin ${REPOSITORY_URL}
- sam build
- sam deploy --no-confirm-changeset --no-fail-on-empty-changeset
only:
- master
This alphine version points to:
https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
which installs python3.8 and now sam is able to package/build the rest of the lambda functions.
QUESTION
Python cfn_tools module won't load in AWS CodeBuild running in AWS CodePipeline
Asked 2021-Dec-20 at 19:11I have been getting the following error in my CodeBuild execution:
ModuleNotFoundError: No module named 'cfn_tools'
Interesting note, the first time I ran this through CodeBuild with this module I had no issues. It only started happening after I made my next gitHub push that kicked off my pipeline that I saw this. The files that are related to this didn't change, and the modifications in that next push were to an unrelated section of the repo.
I have since tried to do:
pip install cfn-tools
& pip3 install cfn-tools
which mentioned that the module was already installed. These were added to the BuildSpec section. No success - still got the errorpip freeze
also within the BuildSpec. The module shows up, but still get the error.python runtime 3.9 Any assistance would be appreciated.
UPDATE: To add more information I download a .tar.gz file from S3 that contains the python scripts I need for running in this build. I extract the .tar.gz then I run the script that is having the error. Here is the output for when I install cfn-tools and do a pip freeze You will see below that cfn-tools loads and is part of the output of pip freeze but yet when I run my script it give me the above error.
[Container] 2021/12/18 20:02:33 Running command pip3 install cfn-tools
Collecting cfn-tools
Downloading cfn-tools-0.1.6.tar.gz (3.9 kB)
Requirement already satisfied: Click>=6.0 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from cfn-tools) (7.1.2)
Requirement already satisfied: boto3>=1.3.1 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from cfn-tools) (1.18.58)
Requirement already satisfied: s3transfer<0.6.0,>=0.5.0 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from boto3>=1.3.1->cfn-tools) (0.5.0)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from boto3>=1.3.1->cfn-tools) (0.10.0)
Requirement already satisfied: botocore<1.22.0,>=1.21.58 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from boto3>=1.3.1->cfn-tools) (1.21.58)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from botocore<1.22.0,>=1.21.58->boto3>=1.3.1->cfn-tools) (2.8.2)
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from botocore<1.22.0,>=1.21.58->boto3>=1.3.1->cfn-tools) (1.26.7)
Requirement already satisfied: six>=1.5 in /root/.pyenv/versions/3.9.5/lib/python3.9/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.22.0,>=1.21.58->boto3>=1.3.1->cfn-tools) (1.16.0)
Building wheels for collected packages: cfn-tools
Building wheel for cfn-tools (setup.py): started
Building wheel for cfn-tools (setup.py): finished with status 'done'
Created wheel for cfn-tools: filename=cfn_tools-0.1.6-py3-none-any.whl size=5456 sha256=9cd3471445f6552165508b0bd797498a535d3ef264059c9739cc6b72f7b96a26
Stored in directory: /root/.cache/pip/wheels/51/1f/6f/f50a0600d46c29ca31519968efefdc4547e8cda7a756584837
Successfully built cfn-tools
Installing collected packages: cfn-tools
Successfully installed cfn-tools-0.1.6
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the '/root/.pyenv/versions/3.9.5/bin/python3.9 -m pip install --upgrade pip' command.
[Container] 2021/12/18 20:02:36 Running command pip3 freeze
arrow==1.2.0
attrs==21.2.0
aws-lambda-builders==1.8.1
aws-sam-cli==1.33.0
aws-sam-translator==1.39.0
awscli==1.20.58
backports.entry-points-selectable==1.1.0
binaryornot==0.4.4
boto3==1.18.58
botocore==1.21.58
certifi==2021.10.8
**cfn-tools==0.1.6**
chardet==4.0.0
chevron==0.14.0
click==7.1.2
colorama==0.4.3
cookiecutter==1.7.3
dateparser==1.1.0
distlib==0.3.3
docker==4.2.2
docutils==0.15.2
filelock==3.3.0
Flask==1.1.4
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
jinja2-time==0.2.0
jmespath==0.10.0
jsonschema==3.2.0
MarkupSafe==2.0.1
pipenv==2021.5.29
platformdirs==2.4.0
poyo==0.5.0
pyasn1==0.4.8
pyrsistent==0.18.0
python-dateutil==2.8.2
python-slugify==5.0.2
pytz==2021.3
PyYAML==5.4.1
regex==2021.10.8
requests==2.25.1
rsa==4.7.2
s3transfer==0.5.0
serverlessrepo==0.1.10
six==1.16.0
text-unidecode==1.3
tomlkit==0.7.2
tzlocal==3.0
urllib3==1.26.7
virtualenv==20.8.1
virtualenv-clone==0.5.7
watchdog==2.1.2
websocket-client==1.2.1
Werkzeug==1.0.1
ANSWER
Answered 2021-Dec-20 at 19:11The module I was trying to install wasn't the one that was being used.
The module that needed to be installed was cfn_flip
it has the cfn_tools
module that the code was trying to use. The CodeBuild didn't have it installed, so how it worked on the first run is still a mystery.
QUESTION
How to properly create a Dynamodb table with SAM
Asked 2021-Dec-09 at 07:14Just getting started with AWS SAM. Wanted to create a CRUD micro service using Lambda and DynamoDB My template.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: >-
A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway.
Resources:
microservicehttpendpoint:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs12.x
CodeUri: .
Description: >-
A simple backend (read/write to DynamoDB) with a RESTful API endpoint using Amazon API Gateway.
MemorySize: 512
Timeout: 10
Policies:
- DynamoDBCrudPolicy:
TableName: MyTable
Events:
Api1:
Type: Api
Properties:
Path: /MyResource
Method: ANY
MyTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey: name
TableName: dynocrud-table
I would expect three resources to be created: a) Lambda, b) Api Gateway endpoint, 3) DynamoDB table The Lambda and the API Gateway endpoint are being created as expected, but no DynamoDB table and no errors. Here is the cli output:
sam deploy
Uploading to dyno-crud/5c01af22215fe32fe7f18fa00be 5706 / 5706 (100.00%)
Deploying with following values
===============================
Stack name : dyno-crud
Region : us-east-1
Confirm changeset : True
Disable rollback : False
Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-141rt5mvjki0m
Capabilities : ["CAPABILITY_IAM"]
Parameter overrides : {"TableNameParameter": "dynocrud-table"}
Signing Profiles : {}
Initiating deployment
=====================
Uploading to dyno-crud/d085f2bf53ae0ab235eabed4814.template 897 / 897 (100.00%)
Waiting for changeset to be created..
CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
-----------------------------------------------------------------------------------------------------------------
+ Add ServerlessRestApiDeploymen AWS::ApiGateway::Deploymen N/A
t1fee5cc247 t
+ Add ServerlessRestApiProdStage AWS::ApiGateway::Stage N/A
+ Add ServerlessRestApi AWS::ApiGateway::RestApi N/A
+ Add microservicehttpendpointAp AWS::Lambda::Permission N/A
i1PermissionProd
+ Add microservicehttpendpointRo AWS::IAM::Role N/A
le
+ Add microservicehttpendpoint AWS::Lambda::Function N/A
-----------------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:us-east-1:458815622243:changeSet/samcli-deploy1639025652/bcbadc92-6106-4cb4-b551-54f3b9774936
Previewing CloudFormation changeset before deployment
======================================================
Deploy this changeset? [y/N]: y
2021-12-08 22:54:43 - Waiting for stack create/update to complete
CloudFormation events from stack operations
-----------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
-----------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::IAM::Role microservicehttpendpointRo -
le
CREATE_IN_PROGRESS AWS::IAM::Role microservicehttpendpointRo Resource creation
le Initiated
CREATE_COMPLETE AWS::IAM::Role microservicehttpendpointRo -
le
CREATE_IN_PROGRESS AWS::Lambda::Function microservicehttpendpoint -
CREATE_IN_PROGRESS AWS::Lambda::Function microservicehttpendpoint Resource creation
Initiated
CREATE_COMPLETE AWS::Lambda::Function microservicehttpendpoint -
CREATE_IN_PROGRESS AWS::ApiGateway::RestApi ServerlessRestApi -
CREATE_COMPLETE AWS::ApiGateway::RestApi ServerlessRestApi -
CREATE_IN_PROGRESS AWS::ApiGateway::RestApi ServerlessRestApi Resource creation
Initiated
CREATE_IN_PROGRESS AWS::Lambda::Permission microservicehttpendpointAp -
i1PermissionProd
CREATE_IN_PROGRESS AWS::Lambda::Permission microservicehttpendpointAp Resource creation
i1PermissionProd Initiated
CREATE_IN_PROGRESS AWS::ApiGateway::Deploymen ServerlessRestApiDeploymen -
t t1fee5cc247
CREATE_IN_PROGRESS AWS::ApiGateway::Deploymen ServerlessRestApiDeploymen Resource creation
t t1fee5cc247 Initiated
CREATE_COMPLETE AWS::ApiGateway::Deploymen ServerlessRestApiDeploymen -
t t1fee5cc247
CREATE_IN_PROGRESS AWS::ApiGateway::Stage ServerlessRestApiProdStage -
CREATE_IN_PROGRESS AWS::ApiGateway::Stage ServerlessRestApiProdStage Resource creation
Initiated
CREATE_COMPLETE AWS::ApiGateway::Stage ServerlessRestApiProdStage -
CREATE_COMPLETE AWS::Lambda::Permission microservicehttpendpointAp -
i1PermissionProd
CREATE_COMPLETE AWS::CloudFormation::Stack dyno-crud -
-----------------------------------------------------------------------------------------------------------------
Successfully created/updated stack - dyno-crud in us-east-1
What should I change in order for the DynamoDB table to be created along the side with other resources?
ANSWER
Answered 2021-Dec-09 at 07:14Please ensure your yaml file is properly indented. The Type:
should be indented below the name of the resource, e.g.
MyTable:
Type: AWS::Serverless::SimpleTable <-- indented here
Properties:
PrimaryKey: name
TableName: dynocrud-table
QUESTION
Why does AWS SAM CLI 1.33.0 crash with _regex.cpython-38-darwin.so no suitable image found on Apple M1 chips?
Asked 2021-Oct-21 at 01:20Today I updated to AWS SAM CLI
version 1.33.0. Then it started crashing making issues during the deployment. When I run the command sam deploy
or sam deploy --guided
, it throws the following error
Traceback (most recent call last):
File "/opt/homebrew/bin/sam", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
do_cli(
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
from samcli.commands.deploy.deploy_context import DeployContext
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/deploy_context.py", line 32, in <module>
from samcli.lib.deploy.deployer import Deployer
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
from samcli.lib.utils.time import utc_to_timestamp
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
import dateparser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
from .date import DateDataParser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
import regex as re
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
from .regex import *
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/regex.py", line 419, in <module>
import regex._regex_core as _regex_core
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex_core.py", line 21, in <module>
import regex._regex as _regex
ImportError: dlopen(/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so, 2): no suitable image found. Did find:
/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so: code signature in (/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library
yohanweerasinghe@Yohans-MacBook-Pro amazon-s3-presigned-urls-aws-sam % sam deploy --guided
Traceback (most recent call last):
File "/opt/homebrew/bin/sam", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
do_cli(
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
from samcli.commands.deploy.deploy_context import DeployContext
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/deploy_context.py", line 32, in <module>
from samcli.lib.deploy.deployer import Deployer
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
from samcli.lib.utils.time import utc_to_timestamp
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
import dateparser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
from .date import DateDataParser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
import regex as re
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
yohanweerasinghe@Yohans-MacBook-Pro amazon-s3-presigned-urls-aws-sam % sam deploy --guided
Traceback (most recent call last):
File "/opt/homebrew/bin/sam", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
do_cli(
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
from samcli.commands.deploy.deploy_context import DeployContext
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/deploy_context.py", line 32, in <module>
from samcli.lib.deploy.deployer import Deployer
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
from samcli.lib.utils.time import utc_to_timestamp
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
import dateparser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
from .date import DateDataParser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
import regex as re
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
yohanweerasinghe@Yohans-MacBook-Pro amazon-s3-presigned-urls-aws-sam % sam deploy --guided
Traceback (most recent call last):
File "/opt/homebrew/bin/sam", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
do_cli(
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
from samcli.commands.deploy.deploy_context import DeployContext
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/deploy_context.py", line 32, in <module>
from samcli.lib.deploy.deployer import Deployer
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
from samcli.lib.utils.time import utc_to_timestamp
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
import dateparser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
from .date import DateDataParser
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
import regex as re
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
from .regex import *
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/regex.py", line 419, in <module>
import regex._regex_core as _regex_core
File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex_core.py", line 21, in <module>
import regex._regex as _regex
ImportError: dlopen(/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so, 2): no suitable image found. Did find:
/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so: code signature in (/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library
I am on MacOS Big Sir 11.6, M1 Chip pro.
How can I fix this issue? Or possibly revert back to the former version of SAM?
UPDATE
This is the output for the command brew info aws-sam-cli
aws/tap/aws-sam-cli: stable 1.33.0, HEAD
AWS SAM CLI 🐿 is a tool for local development and testing of Serverless applications
https://github.com/awslabs/aws-sam-cli/
Conflicts with:
aws-sam-cli-rc (because both install the 'sam' binary)
/opt/homebrew/Cellar/aws-sam-cli/1.33.0 (5,872 files, 108.7MB) *
Built from source on 2021-10-16 at 13:50:40
From: https://github.com/aws/homebrew-tap/blob/HEAD/Formula/aws-sam-cli.rb
==> Dependencies
Required: python@3.8 ✔
==> Options
--HEAD
Install HEAD version
Please check below the output for brew search aws-sam-cli
command
==> Formulae
aws/tap/aws-sam-cli ✔ aws/tap/aws-sam-cli-nightly
aws/tap/aws-sam-cli-beta-acc aws/tap/aws-sam-cli-rc
aws/tap/aws-sam-cli-beta-cdk aws-sam-cli-rc
ANSWER
Answered 2021-Oct-18 at 17:47We have identified the issue and a fix is on the way. The issue is a version of regex. We need to pin to a specific version (2021.9.30) as later ones are having issues on M1. A new version of the CLI will address this.
For now, the workarounds are
/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/bin/pip3 install regex==2021.9.30
pip install regex==2021.9.30
QUESTION
VSCode Debugger unable to resolve non-existent files while locally debugging AWS Lambda
Asked 2021-Oct-13 at 18:13I have a AWS Lambda function that I am attempting to step-through debug with VSCode. I am running into an issue where the behaviour of the debugger and VSCode does not make sense, claiming it cannot resolve non-existent files from paths that it should not be looking for these packages at.
The lambda function has been tested locally using the aws-sam-cli
's sam build
and sam local invoke
functionality. The lambda correctly takes a JSON event with -e
, and returns the expected response. This has been tested with the following setup for its SAM template:
Resources:
MyLambdaFunction:
Type: AWS::Serverless::Function
Metadata:
DockerTag: python3.8-v1
DockerContext: .
Dockerfile: Dockerfile
Properties:
PackageType: Image
The launch.json
, referenced from https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-config-ref.html, is configured as follows:
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "MyLambdaFunction",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/path/to/template.yaml",
"logicalId": "MyLambdaFunction"
},
"lambda": {
"runtime": "python3.8",
"payload": {
"path": "${workspaceFolder}/path/to/input.json"
},
"environmentVariables": {}
}
}
]
}
When attempting to debug via Run > Start Debugging
in VSCode, the docker build completes successfully, and the debugger attaches as per the AWS Toolkit logs. The Dockerfile in question is as follows:
FROM amazon/aws-lambda-python:3.8
COPY index.py requirements.txt ./
ADD mymodules ./mymodules
RUN python3.8 -m pip install -r requirements.txt -t .
CMD ["index.lambda_handler"]
After setting a breakpoint on the first line of index.py
, which is import time
, the debugger stops as expected and all is fine. When I begin to step through the lambda code, there is another import from one of my modules where I am importing from elasticsearch import Elasticsearch
. This is where the first issue appears. VSCode throws an error window in the bottom right with the following message:
Unable to open 'socks.py': Unable to read file
'/Users/me/path/to/app/dir/lambdacode/urllib3/contrib/socks.py'
(Error: Unable to resolve nonexistent file
'/Users/me/path/to/app/dir/lambdacode/urllib3/contrib/socks.py'
Where lambdacode
is the root directory containing the lambda code, module directories, requirement.txt, etc.
I am unable to determine why the debugger is looking for these packages at this workspace path. It seems as if the debugger is not utilizing the docker container at all, since it is looking locally for the packages. For reference, urllib3
is installed system wide on my machine, installed in my virtual environment, and installed in the docker container in question.
Why is the debugger attempting to look exactly here in my workspace folder for the package, and is not utilizing the docker container? Is this a behaviour that I can change somehow? Even after stepping over this import and ignoring the error, there continues to be identical errors for other libraries such as dateutil
etc, which are also installed everywhere that makes sense.
I have confirmed this is an issue with this simple import statement, as I pulled an AWS SAM example with sam init
, and chose the Hello World Image Example for Python3.8, confirmed it debugged as-is, added the import and the requirement for elasticsearch, and encountered the same error when I tried to run the debugger again.
Any insight or help would be appreciated.
ANSWER
Answered 2021-Oct-13 at 18:13Solved. It relates to debugpy. See more here:
QUESTION
AWS Cloudformation: How to fix "Api Event must reference an Api in the same template" error?
Asked 2021-Aug-30 at 11:56I am trying to split my stack into nested stack because i hit the AWS Max stack resource limit. I am building a REST API. I want to use a one API Gateway for all the stacks. Below is my code.
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
aws-restapi
Sample SAM Template for aws-restapi
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 5
VpcConfig:
SecurityGroupIds:
- sg-041f2xxxd921e8e
SubnetIds:
- subnet-03xxxb2d
- subnet-c4dxxxcb
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
GetAllAccountingTypesFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/accounting-types/accountingtypes-getall.getallaccountingtypes
Runtime: nodejs14.x
Events:
GetAllAccountingTypesAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /accountingtypes/getall
Method: get
RestApiId:
Ref: ApiGatewayApi
GetAccountingTypeByIDFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/accounting-types/accountingtypes-byid.getbyid
Runtime: nodejs14.x
Events:
GetAllAccountingTypesAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /accountingtypes/getbyid
Method: get
RestApiId:
Ref: ApiGatewayApi
NestedStackTwo:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: nestedstack.yaml
LambdaRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- ec2:DescribeNetworkInterfaces
- ec2:CreateNetworkInterface
- ec2:DeleteNetworkInterface
- ec2:DescribeInstances
- ec2:AttachNetworkInterface
Resource: '*'
Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for functions"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
nestedstack.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
aws-restapi
Sample SAM Template for aws-restapi
Globals:
Function:
Timeout: 5
VpcConfig:
SecurityGroupIds:
- sg-041f2459dcd921e8e
SubnetIds:
- subnet-03xxxx2d
- subnet-c4dxxxxcb
Parameters:
ApiId: ApiGatewayApi
Resources:
GetAllPromotionsFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/promotions/promotions-getall.getAllPromotions
Runtime: nodejs14.x
Events:
GetAllPromotionsAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /promotions/getall
Method: get
RestApiId:
Ref: !Ref ApiId
SavePromotionsFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/promotions/promotions-save.savePromotions
Runtime: nodejs14.x
Events:
SavePromotionsAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /promotions/save
Method: post
RestApiId:
Ref: !Ref ApiId
UpdatePromotionsFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/promotions/promotions-update.updatePromotions
Runtime: nodejs14.x
Events:
UpdatePromotionsAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /promotions/update
Method: post
RestApiId:
Ref: !Ref ApiId
GetAllStaticInfoFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/static-info/staticinfo-getall.getAllStaticInfo
Runtime: nodejs14.x
Events:
GetAllStaticInfoAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /staticinfo/getall
Method: get
RestApiId:
Ref: !Ref ApiId
SaveStaticInfoFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/static-info/staticinfo-save.saveStaticInfo
Runtime: nodejs14.x
Events:
SaveStaticInfoAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /staticinfo/save
Method: post
RestApiId:
Ref: !Ref ApiId
UpdateStaticInfoFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: aws-restapi/
Handler: source/static-info/staticinfo-update.updateStaticInfo
Runtime: nodejs14.x
Events:
UpdateStaticInfoAPIEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /staticinfo/update
Method: post
RestApiId:
Ref: !Ref ApiId
However, I can't build this project with sam build
. I get the following error.
InvalidSamDocumentException(
samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('GetAllPromotionsFunction', 'Event with id [GetAllPromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.')
Above error is generated for all the functions in the nested stack. If you need the full stacktrace, it is below.
Traceback (most recent call last):
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 68, in run_plugins
parser.parse(template_copy, all_plugins) # parse() will run all configured plugins
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 88, in parse
sam_plugins.act(LifeCycleEvents.before_transform_template, sam_template)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/__init__.py", line 136, in act
raise ex
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/__init__.py", line 133, in act
getattr(plugin, method_name)(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samtranslator/plugins/api/implicit_api_plugin.py", line 100, in on_before_transform_template
raise InvalidDocumentException(errors)
samtranslator.model.exceptions.InvalidDocumentException: [InvalidResourceException('GetAllPromotionsFunction', 'Event with id [GetAllPromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('SavePromotionsFunction', 'Event with id [SavePromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('UpdatePromotionsFunction', 'Event with id [UpdatePromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('GetAllStaticInfoFunction', 'Event with id [GetAllStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('SaveStaticInfoFunction', 'Event with id [SaveStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('UpdateStaticInfoFunction', 'Event with id [UpdateStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.')]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/homebrew/bin/sam", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/commands/build/command.py", line 210, in cli
do_cli(
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/commands/build/command.py", line 279, in do_cli
with BuildContext(
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/commands/build/build_context.py", line 84, in __enter__
self._stacks, remote_stack_full_paths = SamLocalStackProvider.get_stacks(
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_stack_provider.py", line 242, in get_stacks
stacks_in_child, remote_stack_full_paths_in_child = SamLocalStackProvider.get_stacks(
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_stack_provider.py", line 236, in get_stacks
current = SamLocalStackProvider(
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_stack_provider.py", line 51, in __init__
self._template_dict = self.get_template(
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/sam_base_provider.py", line 189, in get_template
template_dict = SamTranslatorWrapper(template_dict, parameter_values=parameters_values).run_plugins()
File "/opt/homebrew/Cellar/aws-sam-cli/1.29.0/libexec/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 70, in run_plugins
raise InvalidSamDocumentException(
samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('GetAllPromotionsFunction', 'Event with id [GetAllPromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('SavePromotionsFunction', 'Event with id [SavePromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('UpdatePromotionsFunction', 'Event with id [UpdatePromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('GetAllStaticInfoFunction', 'Event with id [GetAllStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('SaveStaticInfoFunction', 'Event with id [SaveStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.'), InvalidResourceException('UpdateStaticInfoFunction', 'Event with id [UpdateStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.')] ('GetAllPromotionsFunction', 'Event with id [GetAllPromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.') ('GetAllStaticInfoFunction', 'Event with id [GetAllStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.') ('SavePromotionsFunction', 'Event with id [SavePromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.') ('SaveStaticInfoFunction', 'Event with id [SaveStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.') ('UpdatePromotionsFunction', 'Event with id [UpdatePromotionsAPIEvent] is invalid. Api Event must reference an Api in the same template.') ('UpdateStaticInfoFunction', 'Event with id [UpdateStaticInfoAPIEvent] is invalid. Api Event must reference an Api in the same template.')
How can I fix this?
ANSWER
Answered 2021-Aug-30 at 11:56If you look into the documentation for the API Event for the serverless function, they write:
RestApiId Identifier of a RestApi resource, which must contain an operation with the given path and method. Typically, this is set to reference an AWS::Serverless::Api resource defined in this template.
If you don't define this property, AWS SAM creates a default AWS::Serverless::Api resource using a generated OpenApi document. That resource contains a union of all paths and methods defined by Api events in the same template that do not specify a RestApiId.
This cannot reference an AWS::Serverless::Api resource defined in another template.
template.yaml:
NestedStackTwo:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: nestedstack.yaml
Parameters:
ApiId: !Ref ApiGatewayApi
nestedstack.yaml:
Parameters:
ApiId:
Type: string
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
HTTPS
https://github.com/aws/aws-sam-cli.git
CLI
gh repo clone aws/aws-sam-cli
SSH
git@github.com:aws/aws-sam-cli.git
Share this Page
See Similar Libraries in
by public-apis
by typicode
by iptv-org
by tiangolo
by beego
See all REST Libraries
by aws Python
by aws TypeScript
by aws Python
by aws Python
by aws Go
See all Libraries by this author
by tiangolo
by encode
by dropwizard
by aws
by kubernetes-client
See all REST Libraries
by richadams
by verhas
by kongchen
by pagarme
by DeBortoliWines
See all REST Libraries
by biesior
by imysak
by richadams
by verhas
by maxdemarzi
See all REST Libraries
by nok
by maxdemarzi
by kongchen
by pagarme
by timols
See all REST Libraries
by cyberark
by danielmitterdorfer
by feroult
by rzari
by google
See all REST Libraries
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source