Code Monkey home page Code Monkey logo

amplify-js-local's Introduction

⚡ We are thrilled to announce the release of LocalStack 3.4

LocalStack - A fully functional local cloud stack

CircleCI Coverage Status PyPI Version Docker Pulls PyPi downloads Backers on Open Collective Sponsors on Open Collective PyPI License Code style: black Ruff Twitter

LocalStack is a cloud software development framework to develop and test your AWS applications locally.

OverviewInstallQuickstartRunUsageReleasesContributing
📖 Docs💻 Pro version☑️ LocalStack coverage


Overview

LocalStack is a cloud service emulator that runs in a single container on your laptop or in your CI environment. With LocalStack, you can run your AWS applications or Lambdas entirely on your local machine without connecting to a remote cloud provider! Whether you are testing complex CDK applications or Terraform configurations, or just beginning to learn about AWS services, LocalStack helps speed up and simplify your testing and development workflow.

LocalStack supports a growing number of AWS services, like AWS Lambda, S3, Dynamodb, Kinesis, SQS, SNS, and many more! The Pro version of LocalStack supports additional APIs and advanced features. You can find a comprehensive list of supported APIs on our ☑️ Feature Coverage page.

LocalStack also provides additional features to make your life as a cloud developer easier! Check out LocalStack's User Guides for more information.

Install

The quickest way get started with LocalStack is by using the LocalStack CLI. It enables you to start and manage the LocalStack Docker container directly through your command line. Ensure that your machine has a functional docker environment installed before proceeding.

Brew (macOS or Linux with Homebrew)

Install the LocalStack CLI through our official LocalStack Brew Tap:

brew install localstack/tap/localstack-cli

Binary download (MacOS, Linux, Windows)

If Brew is not installed on your machine, you can download the pre-built LocalStack CLI binary directly:

  • Visit localstack/localstack-cli and download the latest release for your platform.
  • Extract the downloaded archive to a directory included in your PATH variable:
    • For MacOS/Linux, use the command: sudo tar xvzf ~/Downloads/localstack-cli-*-darwin-*-onefile.tar.gz -C /usr/local/bin

PyPI (MacOS, Linux, Windows)

LocalStack is developed using Python. To install the LocalStack CLI using pip, run the following command:

python3 -m pip install localstack

The localstack-cli installation enables you to run the Docker image containing the LocalStack runtime. To interact with the local AWS services, you need to install the awslocal CLI separately. For installation guidelines, refer to the awslocal documentation.

Important: Do not use sudo or run as root user. LocalStack must be installed and started entirely under a local non-root user. If you have problems with permissions in macOS High Sierra, install with pip install --user localstack

Quickstart

Start LocalStack inside a Docker container by running:

 % localstack start -d

     __                     _______ __             __
    / /   ____  _________ _/ / ___// /_____ ______/ /__
   / /   / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
  / /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
 /_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|

 💻 LocalStack CLI 3.4.0
 👤 Profile: default

[12:47:13] starting LocalStack in Docker mode 🐳                       localstack.py:494
           preparing environment                                       bootstrap.py:1240
           configuring container                                       bootstrap.py:1248
           starting container                                          bootstrap.py:1258
[12:47:15] detaching                                                   bootstrap.py:1262

You can query the status of respective services on LocalStack by running:

% localstack status services
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Service                  ┃ Status      ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ acm                      │ ✔ available │
│ apigateway               │ ✔ available │
│ cloudformation           │ ✔ available │
│ cloudwatch               │ ✔ available │
│ config                   │ ✔ available │
│ dynamodb                 │ ✔ available │
...

To use SQS, a fully managed distributed message queuing service, on LocalStack, run:

% awslocal sqs create-queue --queue-name sample-queue
{
    "QueueUrl": "http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/sample-queue"
}

Learn more about LocalStack AWS services and using them with LocalStack's awslocal CLI.

Running

You can run LocalStack through the following options:

Usage

To start using LocalStack, check out our documentation.

To use LocalStack with a graphical user interface, you can use the following UI clients:

Releases

Please refer to GitHub releases to see the complete list of changes for each release. For extended release notes, please refer to the LocalStack Discuss.

Contributing

If you are interested in contributing to LocalStack:

We are thankful for all the contributions and feedback we receive.

Get in touch

Get in touch with the LocalStack Team to report 🐞 issues, upvote 👍 feature requests, 🙋🏽 ask support questions, or 🗣️ discuss local cloud development:

Contributors

We are thankful to all the people who have contributed to this project.

Backers

We are also grateful to all our backers who have donated to the project. You can become a backer on Open Collective.

Sponsors

You can also support this project by becoming a sponsor on Open Collective. Your logo will show up here along with a link to your website.

License

Copyright (c) 2017-2024 LocalStack maintainers and contributors.

Copyright (c) 2016 Atlassian and others.

This version of LocalStack is released under the Apache License, Version 2.0 (see LICENSE). By downloading and using this software you agree to the End-User License Agreement (EULA).

amplify-js-local's People

Contributors

dcbartlett avatar pinzon avatar whummer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

dahannajr pinzon

amplify-js-local's Issues

Does not seem to work

Hey, tried this library on amplify version 6.3.1 (existing project), but it does not seem to mock the endpoints (the project is still accessing the AWS cloud) -- any thoughts?

EDIT: I'm actually getting this error: An error occurred during the push operation: Inaccessible host: 'localhost' at port '4566'. This service may not be available in the 'us-east-1' region.

^ most likely this is due to the different docker instances, I'll try again shortly.

UPDATE: sorry it was my bad, had to use docker network instead of localhost, seems to work just fine :) thx!

Issues with Next13, cognito endpoint not mocked properly

Hello, when using the library with Next13 I've started encountering issues, seemingly the signup functionality still hits the real cognito endpoint, while the signup doesn't.

For signup
Client.js:102 POST https://cognito-idp.eu-central-1.amazonaws.com/ 400

For signin

Client.js:102 POST https://localhost.localstack.cloud:4566/ 400

This is how I try and set it up

lib/amplify.ts

'use client'

import { Amplify, Analytics, Logger, Auth } from "aws-amplify";
import { config } from "@/lib/config";
import { logger } from "./logger";
import applyPatches from 'amplify-js-local/lib/es6';

export const configureAmplify = () => {
	const isLocal = config.environment == 'local'
	isLocal && Analytics.disable();

	Logger.LOG_LEVEL = isLocal ? "INFO" : "INFO";
	try {
		logger.debug("configuring amplify")
		if (isLocal) {
			logger.debug("applyPatches")
			applyPatches();
		}

		console.log(config)

		const awsConfig = {
			Auth: {
				region: config.aws.region,
				userPoolId: config.aws.userPoolID,
				userPoolWebClientId: config.aws.userPoolClientID,
				mandatorySignIn: true,
			}
		}
		Amplify.configure(awsConfig)
		Auth.configure(awsConfig.Auth)

	} catch (error) {
		console.error("error occured during amplify setup", error);
	}
};

I use this inside my component

components/protected.tsx

'use client'

import React, { PropsWithChildren } from "react";
import { Authenticator } from "@aws-amplify/ui-react"
import { configureAmplify } from "@/lib/amplify";

configureAmplify()

export default function Protected({ children }: PropsWithChildren) {
	return (
		<Authenticator>
			{children}
		</Authenticator>
	);
};

Which is used directly in the app/layout.tsx

import "@/styles/globals.css";
import "@aws-amplify/ui-react/styles.css";

import SiteHeader from "@/components/site-header";
import TailwindIndicator from "@/components/tailwind-indicator";
import ThemeProvider from "@/components/theme-provider";
import { fontSans } from "@/lib/fonts";
import { cn } from "@/lib/utils";

import Protected from "@/components/auth/protected";
import { config } from "@/lib/config";

interface RootLayoutProps {
	children: React.ReactNode;
}

export default function RootLayout({ children }: RootLayoutProps) {
	return (
		<>
			<html lang="en" suppressHydrationWarning>
				<head />
				<body
					className={cn(
						"min-h-screen bg-background font-sans antialiased",
						fontSans.variable,
					)}
				>
					<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
						<div className="w-full min-h-screen flex items-center justify-center">
							<Protected>
								<div className="relative flex min-h-screen flex-col">
									<SiteHeader />
									<div className="flex-1">{children}</div>
								</div>
							</Protected>
						</div>
						<TailwindIndicator />
					</ThemeProvider>
				</body>
			</html>
		</>
	);
}

Also in general, the library is full of warnings since it uses the v2 sdk, it also ignores all of the thrown errors so its quite hard to debug if anything is wrong.

  ⚠ ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 Critical dependency: the request of a dependency is an expression

 Import trace for requested module:
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/es6.js
 ./lib/amplify.ts
 ./components/auth/protected.tsx

 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 Module not found: Can't resolve '@aws-amplify/cli/node_modules' in '/app/node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib'

 Import trace for requested module:
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/es6.js
 ./lib/amplify.ts
 ./components/auth/protected.tsx

 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 Critical dependency: the request of a dependency is an expression

 Import trace for requested module:
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/es6.js
 ./lib/amplify.ts
 ./components/auth/protected.tsx

 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 Critical dependency: the request of a dependency is an expression

 Import trace for requested module:
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/es6.js
 ./lib/amplify.ts
 ./components/auth/protected.tsx

 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 Module not found: Can't resolve '@aws-amplify/cli/node_modules' in '/app/node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib'

 Import trace for requested module:
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/es6.js
 ./lib/amplify.ts
 ./components/auth/protected.tsx

 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 Critical dependency: the request of a dependency is an expression

 Import trace for requested module:
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/index.js
 ../../node_modules/.pnpm/[email protected]/node_modules/amplify-js-local/lib/es6.js

Amplifylocal fails to update the endpoints with newer versions of Amplify>4.41.0

Tested it based on the communication on our Slack channel.

https://localstack-community.slack.com/archives/CMAFN2KSP/p1669094332036849?thread_ts=1669029187.187949&cid=CMAFN2KSP

$ amplifylocal init

Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project awsamplifygraphql
The following configuration will be applied:

Project information
| Name: awsamplifygraphql
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: react
| Source Directory Path: src
| Distribution Directory Path: build
| Build Command: npm.cmd run-script build
| Start Command: npm.cmd run-script start

? Initialize the project with the above configuration? Yes
Using default provider  awscloudformation
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use default
🛑 The security token included in the request is invalid.

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: ea25816d-f629-4d67-b02a-3a962bb2cd6f

Unable to run amplifylocal --version

I have just setup a localstack pro account and I am trying to deploy my existing amplify project to localstack. I have followed the setup instructions and run into this error when I try to run amplifylocal --version:

+ @aws-amplify/[email protected]
added 1206 packages from 726 contributors and updated 6 packages in 49.448s
PS C:\Users\Emily Cheyne\source\repos\LocalSecurity\client-app> npm install -g amplify-js-local
C:\Users\Emily Cheyne\AppData\Roaming\npm\amplifylocal -> C:\Users\Emily Cheyne\AppData\Roaming\npm\node_modules\amplify-js-local\bin\amplifylocal
+ [email protected]
updated 1 package in 0.131s
PS C:\Users\Emily Cheyne\source\repos\LocalSecurity\client-app> amplifylocal --version
internal/modules/cjs/loader.js:960
  throw err;
  ^

Error: Cannot find module 'esm'
Require stack:
- C:\Users\Emily Cheyne\AppData\Roaming\npm\node_modules\amplify-js-local\bin\amplifylocal
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\Emily Cheyne\AppData\Roaming\npm\node_modules\amplify-js-local\bin\amplifylocal:10:13)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Emily Cheyne\\AppData\\Roaming\\npm\\node_modules\\amplify-js-local\\bin\\amplifylocal'
  ]
}

Cannot get basic Amplify project to work

Tried to integrate with an existing project but this failed due to localstack S3 buckets not holding existing environments (expected, but needs workaround)

I then tried to create a fresh amplify project, using this CLI and Localstack Pro

mkdir testlocal
cd testlocal
amplifylocal init
amplifylocal add api
amplifylocal push

...

⠦ Updating resources in the cloud. This may take a few minutes...Error updating cloudformation stack
⠦ Updating resources in the cloud. This may take a few minutes...

Following resources failed

✖ An error occurred when pushing the resources to the cloud

Resource is not in the state stackUpdateComplete
An error occurred during the push operation: Resource is not in the state stackUpdateComplete

Followed most of the default prompts for add and push -- generating a new schema.graphql from the Todo example, and choosing an AWS profile for auth.

In the localstack logs I see a few errors about not well-formed XML responses:

AWS::CloudFormation::Stack: Unable to parse response (not well-formed (invalid token): line 3, column 1074), invalid XML received

Env info

localstack --version
0.12.9.1
amplifylocal --version
4.48.0
amplify --version
4.48.0
node --version
v15.14.0
npm --version
7.10.0
python --version
Python 2.7.16
docker --version
Docker version 20.10.5, build 55c4c88

Unable to get existing Amplify project up and running

OS: Mac 10.15.7 (Catalina)
Amplify Version: 4.41.2
Python Version: 3.7.6 (w/pip3)

After signing up for professional and hours of trying to configure this with an existing amplify project I am still not able to get even a first push. The push works when pushing to an AWS stack but fails on localstack.

For the most part the errors look like this with no real indication of what is wrong. Any help is appreciated

Unable to update stack "amplify-jxnapp-local-133700": An error occurred (ValidationError) when calling the CreateStack operation: Unable to create stack "amplify-jxnapp-local-133700-hostingS3AndCloudFront-ebfe70be": Resource deployment loop completed, pending resource changes: [{'Type': 'Resource', 'ResourceChange': {'Action': 'Add', 'LogicalResourceId': 'CloudFrontDistribution', 'PhysicalResourceId': None, 'ResourceType': 'AWS::CloudFront::Distribution', 'Replacement': 'False', 'ChangeSetId': None}}, {'Type': 'Resource', 'ResourceChange': {'Action': 'Add', 'LogicalResourceId': 'PrivateBucketPolicy', 'PhysicalResourceId': None, 'ResourceType': 'AWS::S3::BucketPolicy', 'Replacement': 'False', 'ChangeSetId': None}}, {'Type': 'Resource', 'ResourceChange': {'Action': 'Modify', 'LogicalResourceId': 'CloudFrontDistribution', 'PhysicalResourceId': None, 'ResourceType': 'AWS::CloudFront::Distribution', 'Replacement': 'False', 'ChangeSetId': None}}, {'Type': 'Resource', 'ResourceChange': {'Action': 'Modify', 'LogicalResourceId': 'PrivateBucketPolicy', 'PhysicalResourceId': None, 'ResourceType': 'AWS::S3::BucketPolicy', 'Replacement': 'False', 'ChangeSetId': None}}]
An error occurred during the push operation: Unable to update stack "amplify-jxnapp-local-133700": An error occurred (ValidationError) when calling the CreateStack operation: Unable to create stack "amplify-jxnapp-local-133700-hostingS3AndCloudFront-ebfe70be": Resource deployment loop completed, pending resource changes: [{'Type': 'Resource', 'ResourceChange': {'Action': 'Add', 'LogicalResourceId': 'CloudFrontDistribution', 'PhysicalResourceId': None, 'ResourceType': 'AWS::CloudFront::Distribution', 'Replacement': 'False', 'ChangeSetId': None}}, {'Type': 'Resource', 'ResourceChange': {'Action': 'Add', 'LogicalResourceId': 'PrivateBucketPolicy', 'PhysicalResourceId': None, 'ResourceType': 'AWS::S3::BucketPolicy', 'Replacement': 'False', 'ChangeSetId': None}}, {'Type': 'Resource', 'ResourceChange': {'Action': 'Modify', 'LogicalResourceId': 'CloudFrontDistribution', 'PhysicalResourceId': None, 'ResourceType': 'AWS::CloudFront::Distribution', 'Replacement': 'False', 'ChangeSetId': None}}, {'Type': 'Resource', 'ResourceChange': {'Action': 'Modify', 'LogicalResourceId': 'PrivateBucketPolicy', 'PhysicalResourceId': None, 'ResourceType': 'AWS::S3::BucketPolicy', 'Replacement': 'False', 'ChangeSetId': None}}]

Missing package dependency for 'esm'

Received the below errors when tried to use amplifylocal --version

$ npm install -g amplify-js-local @aws-amplify/cli

added 27 packages, and audited 28 packages in 20s

7 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
$ amplifylocal --version
node:internal/modules/cjs/loader:1029
  throw err;
  ^

Error: Cannot find module 'esm'
Require stack:
- C:\Users\marce\AppData\Roaming\npm\node_modules\amplify-js-local\bin\amplifylocal
    at Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
    at Module._load (node:internal/modules/cjs/loader:872:27)
    at Module.require (node:internal/modules/cjs/loader:1092:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\marce\AppData\Roaming\npm\node_modules\amplify-js-local\bin\amplifylocal:10:13)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\marce\\AppData\\Roaming\\npm\\node_modules\\amplify-js-local\\bin\\amplifylocal'
  ]
}

Missing module: https://www.npmjs.com/package/esm

Amplify Init deploys resources into AWS

Using the latest version of the tool, when creating a backend and trying to deploy it to Localstack, for most services it will reach AWS not LocalStack.

Running amplifylocal init will:

  • Create deployment bucket in AWS S3
  • Create Resources Stack in AWS CFn
  • Create Role into AWS IAM
  • Create the Amplify Backend into LocalStack

Any other addition to the backend like storage or auth will be added through CFn, so they won't be created in LocalStack.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.