Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Using CodeArtifact from SAM
AWS Community Builders  profile imagephilbasford
philbasford forAWS Community Builders

Posted on • Edited on

     

Using CodeArtifact from SAM

Following my blog (https://www.inawisdom.com/amazon/codeartifact-storing-your-dependencies/) I have worked out how you can use private dependancies in CodeArtifact with SAM. The following is a quick guide.

Firstly use the get-authorization-token to get a secure token for CodeArtifact using your AWS CLI and store it in a env var called CODEARTIFACT_AUTH_TOKEN:

export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token --domain my-domain --domain-owner 112333322 --query authorizationToken --output text --profile my-profile --region eu-west-1 )
Enter fullscreen modeExit fullscreen mode

Then create a Pipfile with the CodeArtifact URL but note the use of the CODEARTIFACT_AUTH_TOKEN env var:

[[source]]name = "pypi"url = "https://aws:$CODEARTIFACT_AUTH_TOKEN@my-domain-12333222.d.codeartifact.eu-west-1.amazonaws.com/pypi/PrivatePyPi/simple/"verify_ssl = true[dev-packages]pylint = "*"#awscli = "==1.16.292"#aws-sam-cli = "==0.40.0"flake8 = "*"flake8-print = "==3.1.4"flake8-logging-format = "==0.6.0"flake8-builtins = "==1.4.2"flake8-eradicate = "==0.3.0"flake8-comprehensions = "==3.2.2"flake8-breakpoint = "==1.1.0"flake8-docstrings = "*"flake8-rst-docstrings = "*"flake8-blind-except = "*"pep8-naming = "==0.9.1"cfn-lint = "==0.27.4"pytest = "*"pytest-cov = "==2.8.1"moto = "*"bandit = "*"safety = "*"twine = "*"[packages]pcb_common = "*"[requires]python_version = "3.8"
Enter fullscreen modeExit fullscreen mode

Then use pipenv to create a requirements file:

pipenv lock -r > src/requirements.txt
Enter fullscreen modeExit fullscreen mode

Then use the requirements.txt to pull the dependancies:

sam build  CommonLayer --template template.yaml --use-container --base-dir .
Enter fullscreen modeExit fullscreen mode

The result is the ability to pull your private library. Simple as that!

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
blueskycorner profile image
blueskycorner
Passionate by serverless espacialy on AWS
  • Location
    LYON
  • Work
    Cloud Architect at GFI
  • Joined

Hi,
Impossible to use sam build with a container. It is not able to fetch my private package inside codeartifact.
Is it possible to show the content of your requirements.txt?
Best regards,

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Build On!

Would you like to become an AWS Community Builder? Learn more about the program and apply to join when applications are open next.

More fromAWS Community Builders

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp